FFmpeg: compress a video to a target size

Use two-pass average-bitrate encoding when the complete video must land near a hard file-size target. This one-minute example targets 19 MB for Discord using the same bitrate arithmetic as the calculator.

Copy-paste two-pass FFmpeg commands

Run both commands from the same directory. The first pass analyses the video and writes a pass log; the second writes the final MP4.

ffmpeg -y -i input.mp4 -c:v libx264 -b:v 2475k -preset medium -pass 1 -passlogfile ffmpeg2pass -an -f null -
ffmpeg -i input.mp4 -c:v libx264 -b:v 2475k -preset medium -pass 2 -passlogfile ffmpeg2pass -c:a aac -b:a 128k -movflags +faststart discord.mp4

Calculated video bitrate: 2,475 kbps. Change the duration or target with the video file size calculator.

Two-pass, single-pass bitrate and -fs are not equivalent

Single-pass -b:v

Faster, but the encoder has not analysed later scenes. A motion-heavy ending can receive the wrong share of the budget, and the final size can drift farther from the estimate.

ffmpeg -i input.mp4 -c:v libx264 -b:v 2475k -preset medium -c:a aac -b:a 128k -movflags +faststart discord.mp4

The -fs byte cap

This is a stop-writing threshold, not a target-size strategy. FFmpeg may stop before the final frames, metadata or trailer are complete, especially when the chosen CRF produces data faster than expected.

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -c:a aac -b:a 128k -fs 19922944 discord.mp4

Two-pass average bitrate

Best when size matters more than encode time. The first pass records where the clip is easy or difficult; the second spends the fixed bitrate budget across those scenes.

Calculate bitrate from target MB, duration and audio

The shared calculation reserves MP4 container overhead, divides the remaining bits by duration, and subtracts the audio bitrate. That produces the maximum average video bitrate used in every command on this page. Read the underlying concepts in two-pass encoding and x264 preset.

video kbps = target-size budget per second − audio kbps

Discord, Gmail and WhatsApp examples

These targets come from the same verified platform records used by the compressor and the attachment and video size limits dataset. Each example assumes a one-minute input.

Discord: 19 MB safe target

Verified 2026-11-18. The published primary limit is 20 MB. The command uses the configured safe target.

ffmpeg -y -i input.mp4 -c:v libx264 -b:v 2475k -preset medium -pass 1 -passlogfile discord-pass -an -f null -
ffmpeg -i input.mp4 -c:v libx264 -b:v 2475k -preset medium -pass 2 -passlogfile discord-pass -c:a aac -b:a 128k -movflags +faststart discord.mp4

Gmail: 18 MB safe target

Verified 2026-10-30. The published primary limit is 25 MB. The command uses the configured safe target.

ffmpeg -y -i input.mp4 -c:v libx264 -b:v 2338k -preset medium -pass 1 -passlogfile gmail-pass -an -f null -
ffmpeg -i input.mp4 -c:v libx264 -b:v 2338k -preset medium -pass 2 -passlogfile gmail-pass -c:a aac -b:a 128k -movflags +faststart gmail.mp4

WhatsApp: 15 MB safe target

Verified 2026-11-18. 16 MB is the conservative chat-video reference used by this dataset, not a published WhatsApp hard cap. The command uses the configured safe target.

ffmpeg -y -i input.mp4 -c:v libx264 -b:v 1927k -preset medium -pass 1 -passlogfile whatsapp-pass -an -f null -
ffmpeg -i input.mp4 -c:v libx264 -b:v 1927k -preset medium -pass 2 -passlogfile whatsapp-pass -c:a aac -b:a 128k -movflags +faststart whatsapp.mp4

Why CRF cannot guarantee the final file size

CRF asks for a quality level. It deliberately spends more bits on grain, motion and detailed 4K frames, and fewer on static slides or screen recordings. Because the source decides the bitrate, two videos with the same duration and CRF can finish at very different sizes.

ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k -movflags +faststart discord.mp4

For the tool and library definition, see FFmpeg in the glossary.

How to compress to a target size with FFmpeg

  1. Step 1

    Choose a safe target size

    Use the destination platform’s recommended target rather than encoding at the published hard cap.

  2. Step 2

    Calculate the video bitrate

    Divide the available bits across the duration and subtract the audio bitrate. The command helper on this page uses the shared VidSmaller bitrate calculation.

  3. Step 3

    Run both encoding passes

    The first pass measures scene complexity. The second pass writes H.264 video and AAC audio into the target bitrate budget.

FFmpeg target-size questions

Can FFmpeg guarantee an exact final file size?

No encoder can guarantee the final byte exactly. Two-pass average-bitrate encoding is the closest of these methods because the first pass measures scene complexity before the second allocates the fixed bitrate budget. Leave headroom below a hard platform cap.

Why does CRF not hit a target file size?

CRF targets a quality level, not a byte budget. Easy footage may become tiny while grain, motion or 4K detail can remain large at the same CRF value.

Should I use -fs for a Discord or Gmail limit?

-fs stops writing when the output reaches a byte ceiling, so it can cut the file before the final frames or trailer are written. Use two-pass encoding for a complete video and treat -fs as a blunt emergency cap.

How do I calculate the FFmpeg video bitrate?

Convert the target size to bits, reserve container overhead, divide by duration, then subtract the audio bitrate. The commands on this page use the same shared calculation as the VidSmaller video file size calculator.