Compress a video to a target size (like 25 MB) with ffmpeg: the bitrate maths and two-pass commands
The form says 25 MB maximum and your two-minute clip is 120 MB. Guessing a quality setting and hoping takes several tries. A bit of arithmetic gets it right first time.
Why the maths works
File size is just bitrate multiplied by time. If you fix the size and you know the length, the bitrate is the only thing left to choose. ffmpeg's -b:v sets an average video bitrate; the audio adds its own bitrate on top, and the MP4 container adds a little more. Leaving about 3% headroom keeps the result just under the limit.
| Limit | 1 minute | 2 minutes | 5 minutes | 10 minutes |
|---|---|---|---|---|
| 25 MB | ~3,100 kbps | ~1,490 kbps | ~520 kbps | ~200 kbps |
| 100 MB | ~12,800 kbps | ~6,340 kbps | ~2,460 kbps | ~1,170 kbps |
| 500 MB | very generous | ~32,200 kbps | ~12,800 kbps | ~6,340 kbps |
Video bitrate after 128 kbps of audio and 3% headroom.
What resolution for that bitrate?
Squeezing full HD into a tiny bitrate makes it blocky. A smaller picture at the same bitrate looks sharper, and players scale it up smoothly. As a rough guide for H.264:
| Video bitrate | Looks good at |
|---|---|
| 5,000 kbps and up | 1080p (even 1440p) |
| 2,500 to 5,000 kbps | 1080p |
| 1,200 to 2,500 kbps | 720p |
| 600 to 1,200 kbps | 480p |
| under 600 kbps | 360p, or trim the clip |
Add -vf scale=-2:720 (or 480, 360) to scale the height and keep the shape; -2 keeps the width an even number, which H.264 needs.
Why two passes?
On the first pass ffmpeg only reads the video and notes which scenes are busy and which are calm, writing a small log file. On the second it spends more bits on busy scenes and fewer on still ones, while landing close to the average you asked for. One pass with -b:v also hits the size roughly, but looks worse; a quality setting like -crf 23 looks good but you can't predict the size.
Common snags
- Result slightly over the limit: some sites count 25 MB as 25 × 1,024 × 1,024 bytes and some as 25,000,000. The 3% headroom covers that; if it still fails, ask for a slightly smaller limit.
- "Too tight": a long video under a small limit leaves almost nothing per second. Trim it, drop the audio with
-an, or share a link to the file instead. - Won't play on an older TV or laptop: phone video is often 10-bit HDR HEVC. Encoding with
-c:v libx264 -pix_fmt yuv420p, as the commands here do with libx264, gives a plain 8-bit H.264 file that plays almost anywhere; colours may look a little flatter than the HDR original. - Blocky or smudgy result: that's too few bits for that many pixels. Scale down (720p or 480p) rather than squeezing harder, and avoid re-compressing a file that was already compressed, because detail lost once never comes back. The interactive lesson what happens when you squish a video too much shows why.
- Leftover files: two-pass leaves
ffmpeg2pass-0.logfiles in the folder. They're safe to delete.
Related
Why video smears when skipping (keyframes) · Split a video into parts without re-encoding · Make a GIF smaller instead · File too large for a USB stick (FAT32) · How big a minute of video is · Photo too large to email · How long a video takes to upload · Lossless vs lossy compression · Why squished video goes blocky (interactive lesson)
Questions
How do I compress a video to 25 MB?
Divide 25 MB by the length to get a bitrate: for 2 minutes with 128 kbps audio, use about 1,490 kbps of video at 720p, encoded in two passes with ffmpeg. The calculator writes the exact commands.
What does two-pass encoding do?
The first pass measures how busy each scene is; the second pass spends bits where they're needed while keeping the average bitrate you set, so the file lands close to your target and looks better.
Why is my compressed video still too big?
Usually the audio was left out of the sums, or the site counts megabytes as 1,048,576 bytes. Leave 3% headroom and subtract the audio bitrate, as the calculator does.
Should I use CRF or a bitrate?
Use CRF when you want a steady quality and don't mind the size. Use a bitrate with two passes when the file must fit a limit.
Do I have to upload my video to compress it?
No. ffmpeg runs on your own computer. The calculator only does the arithmetic in your browser and never sees the file.
Published 路 updated .