ffmpeg video compression / specific file size

if you are targeting a certain output file size the best way is to use H.264 and Two-Pass encoding.

There is a great example here but it’s too large to copy-paste:
https://trac.ffmpeg.org/wiki/Encode/H.264#twopass

You calculate your target bitrate using bitrate = target size / duration and you launch ffmpeg two times: one pass analyzes the media and the second does 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 && \
ffmpeg -i input -c:v libx264 -preset medium -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4

Edit: H.265 (HEVC) is even better at compression (50% of H.264 size in some cases) but support is not yet widespread so stick with H.264 for now.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)