Shrink a video to a specific size (in MB)
Have a file size limit to meet? Enter the size you want and the duration: the video bitrate is calculated, then the two ffmpeg commands are generated.
Updated on
Shown in the file's properties.
Lowering the resolution helps when the target size is very small.
Only used by the first command (analysis).
How to use it
- Install ffmpeg if you haven't already.
- Enter the size you want and the duration of the video: the video bitrate is calculated for you.
- Run the two commands one after the other, in the video's folder: the first analyzes, the second encodes.
- Check the resulting file size. If it's slightly over, lower the target size by 1 to 2 MB and try again.
- Then delete the ffmpeg2pass-0.log files created by the first command.
How the bitrate is calculated
The target size, converted to kilobits, is divided by the duration to give the total bitrate in kbps, from which the audio bitrate is subtracted. The calculation keeps a 5% margin for the MP4 container and bitrate variations. With 20 MB for 90 seconds and 96 kbps audio, the video bitrate is about 1,590 kbps.
When to use this method
It's the right choice when a size limit is strict: an email attachment, a form, a platform. If the goal is just to make a video smaller, the quality-based method (CRF) is simpler and gives more consistent quality. For a long video aimed at a small size, the bitrate becomes very low and the picture degrades: it's better to lower the resolution.
If your video is already small
This method aims for a size; it doesn't always reduce it: if the original video is already smaller than the target size, re-compressing it can make it larger. In our tests, a 0.96 MB video grew to 2.4 MB with a 20 MB target. In that case, keep the original file, or use the quality-based method (CRF).
Frequently asked questions
Why two commands?
Two-pass encoding first analyzes the video, then distributes the bitrate to get close to the target size. It's the most reliable method for hitting a specific file size.
Is the final file exactly the size I entered?
No: it's usually a bit smaller. The calculation keeps a 5% margin, and a bitrate cap (the -maxrate and -bufsize options) stops ffmpeg from exceeding the target, which would otherwise happen on low-motion videos. Here, 1 MB equals 1,000,000 bytes.
How do I find out my video's duration?
Open the file's properties, or run ffprobe on the video; it is installed with ffmpeg.
What is -x264-params mbtree=0 for?
It disables an encoder optimization that can make the second pass fail on some videos (the "Incomplete MB-tree stats file" error). It very slightly increases the file size for a given quality.
The resulting file is much smaller than the target size. Is that normal?
Yes, for a very static video (slideshow, screen recording): it doesn't need all the available bitrate, and ffmpeg may display "2pass curve failed to converge". The result is still valid.
ffmpeg shows "Unrecognized option 'fps_mode'". What should I do?
Your version of ffmpeg is older than 5.1. Update ffmpeg, or replace "-fps_mode passthrough" with "-vsync passthrough" in both commands.