Back to roadmaps ffmpeg Course

Video Compression: Bitrate Control and CRF Quality

Reducing video file sizes without unacceptable quality loss is a core FFmpeg use case. The key parameter is the CRF (Constant Rate Factor).


1. Understanding the CRF Parameter

The CRF parameter controls the trade-off between quality and file size:

  • Lower CRF value = Higher quality, larger file size.
  • Higher CRF value = Lower quality, smaller file size.

For H.264 encoding using libx264, the useful CRF range is 0 to 51, where 18 is considered "visually lossless" and 23 is the default. For most web video delivery, a value between 20 and 28 is a good target.


2. Compressing with H.264 (libx264)

# Compress using H.264 with CRF 24 (good balance for web)
ffmpeg -i input.mp4 -c:v libx264 -crf 24 -preset medium -c:a aac -b:a 128k output_compressed.mp4
  • -preset: Controls encoding speed vs compression efficiency. Options range from ultrafast to veryslow. Slower presets produce smaller files at the same CRF.

3. Compressing with H.265 (libx265)

H.265/HEVC typically achieves the same quality as H.264 at roughly half the file size:

# Compress using H.265 with CRF 28 (equivalent quality to H.264 at CRF 24)
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -c:a aac -b:a 128k output_h265.mp4

Note: H.265 requires more CPU time to encode but results in significantly smaller output files.

Published on Last updated: