Video Compression — Choosing Between CRF Mode and Bitrate Mode
When reducing video file size, FFmpeg offers two main approaches: “CRF mode (constant quality)” and “bitrate mode (size/bandwidth control)”. The choice between them affects the balance of output quality, file size, and encoding speed. This article explains the characteristics of each mode and when to use them, with command examples verified in ffmpeg 6.1.
Tested with: ffmpeg 6.1.1 / Ubuntu 24.04
1. Basic Commands for H.264 (libx264) and H.265 (libx265)
Starting with the simplest conversions.
Compress with H.264
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset medium -c:a copy output.mp4
Compress with H.265 (HEVC)
ffmpeg -i input.mp4 -c:v libx265 -crf 28 -preset medium -c:a copy output.mp4
H.265 tends to require less data than H.264 to achieve equivalent visual quality, but encoding takes longer. It may also not play on older devices or players.
2. CRF Mode (Constant Quality)
What is CRF?
CRF (Constant Rate Factor) is a mode that maintains consistent visual quality by dynamically varying the bitrate based on scene complexity. It reduces the bitrate for static scenes and increases it for scenes with a lot of motion, resulting in efficient overall compression.
CRF Value Ranges
| Codec | CRF Range | Lower values | Higher values |
|---|---|---|---|
| libx264 | 0–51 | High quality, large file | Low quality, small file |
| libx265 | 0–51 | High quality, large file | Low quality, small file |
Note: The optimal CRF value varies significantly depending on the content (film, animation, sports footage, etc.) and intended use. The default values shown above (H.264: 23, H.265: 28) are the encoder defaults and are not necessarily optimal for every use case. Adjust while reviewing the actual output.
CRF Mode Example
ffmpeg -i input.mp4 -c:v libx264 -crf 18 -preset slow -c:a copy output.mp4
Lowering the CRF increases quality and also increases file size.
3. Bitrate Mode
This mode specifies a target bitrate for the output. Use it when you need some control over the output file size, or when a streaming platform sets a bitrate cap.
VBR (Variable Bitrate)
ffmpeg -i input.mp4 -c:v libx264 -b:v 2000k -c:a copy output.mp4
-b:v 2000k: Sets the target video bitrate to 2000 kbps
CBR (Constant Bitrate)
CBR is achieved by combining -b:v, -minrate, -maxrate, and -bufsize.
ffmpeg -i input.mp4 -c:v libx264 -b:v 2000k -minrate 2000k -maxrate 2000k -bufsize 4000k -c:a copy output.mp4
CBR is suitable for streaming delivery or environments with bandwidth constraints.
4. 2-Pass Encoding
2-pass encoding first analyzes the video in pass 1 and records statistics, then uses that information in pass 2 to generate output close to the specified bitrate. The official documentation describes it as: “The statistics of the video are recorded in the first pass into a log file…and in the second pass that log file is used to generate the video at the exact requested bitrate.”
This achieves greater accuracy to the target bitrate than simple single-pass bitrate encoding.
ffmpeg -i input.mp4 -c:v libx264 -b:v 2000k -pass 1 -an -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -b:v 2000k -pass 2 -c:a copy output.mp4
This is a set of two commands. In pass 1, -an (no audio) and -f null /dev/null are used to analyze only the video; in pass 2, the actual output is generated.
5. -preset: Speed vs. Quality Trade-off
The -preset option controls the balance between encoding speed and compression efficiency.
Main presets available for libx264 / libx265 (from fastest to slowest):
ultrafast → superfast → veryfast → faster → fast → medium → slow → slower → veryslow
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow -c:a copy output.mp4
ultrafasttoveryfast: Encodes quickly, but tends to produce larger files at the same CRF valuemedium: Default. A good balance for most situationsslowtoveryslow: Takes longer to encode, but tends to produce smaller files at the same CRF value
If time permits, using slow or slower can reduce file size while maintaining the same quality.
6. H.264 vs H.265: Which to Choose?
| Aspect | H.264 (libx264) | H.265 (libx265) |
|---|---|---|
| Compatibility | Very high (almost all environments) | Relatively limited (may not work on older devices) |
| Compression efficiency | Standard | Tends to be more efficient than H.264 |
| Encoding speed | Fast | Slow |
| Licensing | Patented | Patented |
H.264 is the safe choice for distribution or public-facing content that needs broad device compatibility. H.265 is a viable option when storage efficiency is a priority and the playback environment is confirmed to support it.
7. Estimating File Size
Video file size can be roughly estimated with the following formula:
File size (MB) ≈ (video bitrate + audio bitrate) × duration (seconds) ÷ 8 ÷ 1024 ÷ 1024
Example: video 2000 kbps + audio 128 kbps, 10-minute video:
(2000 + 128) × 600 ÷ 8 ÷ 1024 ÷ 1024 ≈ 153 MB
Since CRF mode varies the bitrate depending on content, accurate prediction beforehand is difficult. Use this as a rough reference only.
Related Articles
Tested with: ffmpeg 6.1.1 / Ubuntu 24.04 (GitHub Actions runner)
Primary sources: ffmpeg.org/ffmpeg.html / ffmpeg.org/ffmpeg-codecs.html / ffmpeg.org/ffmpeg-filters.html