Dev.to
7/18/2026

How I make ffmpeg hit an exact file size (the bitrate math nobody explains)
Short summary
Hitting an exact video file size is arithmetic, not guesswork: bitrate = target_bits / duration. Reserve ~2% for container overhead, subtract audio bitrate, and divide the remainder by duration to get video bitrate. Use ffmpeg two-pass encoding so the encoder distributes bits intelligently and the average lands on your target. The author wraps this math in a Rust CLI called DeepShrink.
- •File size = bitrate × duration; flip the equation to solve for bitrate from a target size
- •Reserve ~2% for container overhead and subtract audio budget before calculating video bitrate
- •Two-pass ffmpeg encoding ensures the average bitrate actually hits your target
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



