FFmpeg recipe

FFmpeg: Compress an MP4 to a Target File Size

When you must hit a specific size (e.g. 25 MB for email), two-pass bitrate encoding is the way. Calculate target bitrate, then run two passes.

Command

# duration=60s, target=24MB → bitrate ≈ 24*8/60 = 3200 kbps total
ffmpeg -y -i input.mp4 -c:v libx264 -b:v 3000k -pass 1 -an -f mp4 /dev/null && \
ffmpeg -i input.mp4 -c:v libx264 -b:v 3000k -pass 2 -c:a aac -b:a 128k -y output.mp4
Prefer no terminal?
Use the Video Compressor in your browser
Open Video Compressor

What each flag does

-b:vTarget video bitrate. Computed from desired size and duration: bitrate_kbps ≈ size_MB × 8000 / duration_seconds.
-pass 1First pass: analyze the video to build a bitrate distribution map. No output written.
-pass 2Second pass: encode using the map for optimal bit allocation.
-anNo audio in pass 1 to save time.

Notes & gotchas

  • Two-pass is ~2x slower than single-pass CRF but hits target sizes accurately.
  • On Windows, use NUL instead of /dev/null in pass 1.

Related recipes