How to limit file size with ffmpeg? I want to encode a video, that has a length of 60 seconds, to a target or maximum size of 10 MB.

There are two approaches I know of. One is explained in the FFMPEG-Wiki, and the other one I found in the documentation. Unfortunately, I haven't found an explanation on when to use what method.

Is any of those methods recommended? If not, what are the upsides/downsides of each method?

1) Calculate and set Bitrate to match the length of the video as explained in the ffmpeg-wiki


  (10 MB * 8192 [converts MB to kilobits]) / 60 seconds = ~1365 kbits/s total bitrate
  1365k - 128k (desired audio bitrate) = 1237k video bitrate


ffmpeg -y -i input -c:v copy -preset medium -b:v 1237k -pass 1 -c:a copy -b:a 128k -f mp4 /dev/null &amp;&amp; \
ffmpeg -i input -c:v libx264 -preset medium -b:v 1237k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4


2) Use the -fs parameter and let ffmpeg figure it out.

ffmpeg -i input -c:v copy -c:a copy -preset medium -crf 23 -fs 10485760 output.mp4
The fs parameter will stop the encode once it hits its value. So, if the output hits the 10MB mark while encoding the 15th second, then that's the duration of your output file.

If you want to make sure that the entire file is encoded but it doesn't cross the set target size, then use the bitrate method. To accommodate the muxing overhead and other data within the target size, set your video bitrate slightly lower by, say, 1-2%