FFMPEG COMMAND

Compress a video with FFmpeg

For most files the answer is a constant-quality H.264 encode with a higher CRF and a slower preset. The measured sizes below come from a 9.9 MB 1080p test file.

Verified with FFmpeg 9.0.1 on 26 August 2026. Search intent: ffmpeg compress video.

the command
ffmpeg -i input.mp4 -c:v libx264 -crf 28 -preset slow -c:a aac -b:a 128k -movflags +faststart output.mp4

Constant-quality H.264 at CRF 28, a slower preset for better compression, AAC audio at 128 kbps, and the index moved to the front so the file starts playing before it is fully downloaded. The 1080p test file went from 9.9 MB to 4.7 MB.

Flags, explained

-crf 28
Constant rate factor, 0 to 51 for x264. Higher means smaller and worse. 23 is the default, 28 is a visible but usually acceptable step down for web delivery.
-preset slow
How hard the encoder works. Slower presets compress better at the same CRF; slow is a good trade for offline processing.
-c:a aac -b:a 128k
Audio is often a large share of a small file. 128 kbps AAC is transparent for speech; use 160 to 192 kbps for music.
-movflags +faststart
Writes the MP4 index at the start of the file so browsers can begin playback before the download finishes.
-b:v 1500k -maxrate 1500k -bufsize 3000k
Average, ceiling and buffer size for a capped bitrate. Use it when the delivery bandwidth is the constraint.
-tag:v hvc1
Marks HEVC in MP4 so that Safari, iOS and QuickTime recognise it. Without it they refuse the file.

Variants

Downscale and compress

shell
ffmpeg -i input.mp4 -vf "scale=1280:-2" -c:v libx264 -crf 28 -preset slow -c:a aac -b:a 96k -movflags +faststart output.mp4

Fewer pixels is the biggest lever. 1080p to 720p at the same CRF took the test file from 9.9 MB to 1.2 MB.

Cap the bitrate for streaming

shell
ffmpeg -i input.mp4 -c:v libx264 -b:v 1500k -maxrate 1500k -bufsize 3000k -preset medium -c:a aac -b:a 128k -movflags +faststart output.mp4

Targets 1.5 Mbps with a hard ceiling, which is what a player on a slow connection needs. Quality varies with the content instead of the size. Output: 2.5 MB for 12 s.

H.265 (HEVC) for smaller files on modern players

shell
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -tag:v hvc1 -c:a aac -b:a 128k -movflags +faststart output.mp4

x265 CRF values are not comparable with x264 ones, and results depend on the footage: on our synthetic test pattern the HEVC file came out larger (6.8 MB against 4.7 MB). Measure on your own material, and keep -tag:v hvc1 or Apple devices will not play it.

Pitfalls we hit

  • CRF is not linear. The x264 rule of thumb is that +6 CRF roughly halves the size; going from 23 to 28 on the test file saved 53%.
  • A fast preset with the same CRF gives a bigger file at the same quality, not a worse one. If the file is too large, slow the preset down before raising CRF.
  • x264 and x265 CRF scales differ, and HEVC gains vary with content. Our synthetic pattern got larger with libx265; camera footage usually does not, but only a test on your files tells.
  • Compressing an already compressed file loses quality twice. Keep the highest quality master and compress from that.

How we verified it

Run with FFmpeg 9.0.1 on 26 August 2026 against a 12 s, 1920x1080, 30 fps H.264/AAC file of 9,862,251 bytes. CRF 28 slow → 4,666,669 bytes (53% smaller). 720p CRF 28 → 1,173,666 bytes. 1500k cap → 2,491,456 bytes. libx265 CRF 28 with hvc1 → 6,761,114 bytes, HEVC Main, playable in QuickTime.

The same edit as a typed operation

compress_video exposes a quality level instead of CRF, preset and bitrate knobs, applies encoder defaults tuned for web playback (faststart included) and returns a download URL with the output size. Quality and size stay predictable across inputs.

MCP tool: compress_videoPOST /api/v1/tools/compress-video
request body
{
  "inputs": [{ "id": "main", "url": "https://example.com/video.mp4" }],
  "options": { "quality": "balanced" }
}

FAQ

Which CRF should I use to compress a video?

Start at 23 for a visually transparent web copy, 26 to 28 when size matters more than pixel-level fidelity, and compare a few seconds of output before batch processing. Above 30 artifacts become obvious on most content.

How do I compress a video to a specific size?

Divide the size budget by the duration to get a total bitrate, subtract the audio bitrate, and use the capped bitrate variant with that value for -b:v. Two-pass encoding (-pass 1 and -pass 2) hits the target more precisely.

Is H.265 always smaller than H.264?

Not at the same CRF number, and not on every content. It is usually smaller at equal visual quality on real footage, at the price of slower encoding and fewer players. Test on your own material.

Does compressing reduce the resolution?

No. CRF and bitrate keep the pixel dimensions and reduce detail. Downscaling with the scale filter reduces the resolution, which saves more space when the viewer will not display the video at full size anyway.

Related commands

All FFmpeg commands