The script now exits with a helpful message if target size would be too small.
Removed dependency on grep ( -P switch not implemented in OSX grep).
Renamed variables for readability and consistency.
This anycodings_ffmpeg version keeps the original audio anycodings_ffmpeg quality, and resizes to the target size. You calculate your target bitrate using anycodings_ffmpeg bitrate = target size / duration and you anycodings_ffmpeg launch ffmpeg two times: one pass anycodings_ffmpeg analyzes the media and the second does anycodings_ffmpeg the actual encoding: ffmpeg -y -i input -c:v libx264 -preset medium -b:v 555k -pass 1 -c:a libfdk_aac -b:a 128k -f mp4 /dev/null & \įfmpeg -i input -c:v libx264 -preset medium -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4Įdit: H.265 (HEVC) is even better at anycodings_ffmpeg compression (50% of H.264 size in some anycodings_ffmpeg cases) but support is not yet widespread anycodings_ffmpeg so stick with H.264 for now. There is a great example here but it's anycodings_ffmpeg too large to anycodings_ffmpeg copy-paste: If you are targeting a certain output anycodings_ffmpeg file size the best way is to use H.264 anycodings_ffmpeg and Two-Pass encoding.