Quality controls: CRF, bitrate and presets
Rate control decides how many bits each frame gets. Choose the mode by what has to stay fixed: the quality, the file size, or the bitrate at every moment.
| Mode | You set | Result | Use it for |
|---|---|---|---|
| CRF / constant quality | A quality value | Consistent quality; file size depends on the content | Almost every encode you keep, archive or upload |
| Capped CRF (CRF + VBV) | Quality value plus peak rate/buffer | Constant quality, except that peaks are limited | Streaming and devices with a bitrate limit |
| Two-pass VBR | Average bitrate | Predictable size; quality close to CRF at the same size | Hitting a file size or an average-bitrate requirement |
| One-pass ABR | Average bitrate | Roughly the right size; bits are spent poorly | Live encoding where two passes are impossible |
| CBR | Constant bitrate | Bitrate held constant, with padding if needed | Broadcast and some live transport |
| Constant QP (CQP) | A fixed quantizer | Same quantizer everywhere; wastes bits on hard scenes | Codec development and testing, not delivery |
CRF and constant quality
Section titled “CRF and constant quality”CRF (constant rate factor) is quality-based variable bitrate. The encoder raises or lowers the quantizer from frame to frame and block to block, spending fewer bits where loss is hard to see (fast motion, complex texture) and more where it shows. At the same file size this looks better than constant QP, which ignores where the eye notices errors.
CRF numbers are encoder-specific. They do not mean the same quality across encoders, and sometimes not across versions of one encoder.
| Encoder (FFmpeg name) | Option | Default | Notes |
|---|---|---|---|
x264 (libx264) | -crf | 23 | Lower is better; about ±6 halves or doubles the bitrate. 18–24 covers most uses. |
x265 (libx265) | -crf | 28 | Same 0–51 scale as x264, but the same number does not give the same quality. |
SVT-AV1 (libsvtav1) | -crf | 35 | Range 1–70 (FFmpeg’s -crf accepts up to 63). Upstream suggests 30 as a starting point for 1080p. |
libaom (libaom-av1) | -crf | 32 | Range 0–63. -crf alone is constant quality; adding -b:v makes it constrained quality. |
libvpx (libvpx-vp9) | -crf | 32 | Range 0–63. In current FFmpeg, -crf alone is constant quality; the old -b:v 0 is not needed. |
Hardware encoders have their own constant-quality modes (NVENC -cq, Quick Sync ICQ, and others).
They are not interchangeable with software CRF values; see the
hardware encoder pages.
Presets trade speed for compression efficiency and are also encoder-specific: x264 and x265 use
names (ultrafast … placebo), SVT-AV1 uses numbers where lower is slower and better. Change the
preset to fit your time budget, then adjust CRF until the result looks right. At the same CRF a
slower preset usually gives a smaller file or more detail.
Cap the bitrate with VBV
Section titled “Cap the bitrate with VBV”VBV (video buffering verifier) models a decoder’s input buffer: data arrives at up to -maxrate
and the buffer holds -bufsize bits. Combined with CRF it keeps constant-quality behaviour but
stops peaks from exceeding what a player or connection can take:
ffmpeg -i input.mkv -c:v libx264 -preset slow -crf 20 -maxrate 6M -bufsize 12M -c:a copy output.mkv-maxrate is the peak rate and -bufsize the buffer it is averaged over; you need both. A larger
buffer allows short bursts; a smaller one enforces the limit more strictly. When the cap kicks in,
quality drops in those scenes, so set it from the real limit of the target, not lower. The same
-maxrate/-bufsize options work with libx265, and -maxrate with libsvtav1 turns its CRF mode
into capped CRF.
Hit a file size with two passes
Section titled “Hit a file size with two passes”Work out the video bitrate from the size you want:
video kbit/s = target MiB × 8388.608 / duration in seconds − audio kbit/sFor a 60-minute file of 1,500 MiB with 128 kbit/s audio: 1500 × 8388.608 / 3600 − 128 ≈ 3367 kbit/s.
ffmpeg -i input.mkv -c:v libx264 -preset slow -b:v 3367k -pass 1 -an -f null /dev/nullffmpeg -i input.mkv -c:v libx264 -preset slow -b:v 3367k -pass 2 -c:a libopus -b:a 128k output.mkvThe first pass analyses the whole video and writes a stats file (ffmpeg2pass-0.log); its output
is discarded, and -an skips audio work in that pass. The second pass uses the stats to put bits
where they are needed. With x264, a two-pass encode looks about the same as a CRF encode
that happens to produce the same size, so use two passes when the size matters and CRF otherwise.
For SVT-AV1, multi-pass mainly serves VBR; upstream describes it as not critical in CRF mode. CBR is always single-pass.
Testing settings
Section titled “Testing settings”Test on a short clip that includes the hardest material in the source, and change one thing at a time. Compare the clips by watching them, not just by file size or a single metric score; the quality comparison guide covers metrics and how to use them properly.