ffmpeg -crf: constant rate factor for x264, x265 and AV1
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · ffmpeg version 9.0.2-full_build-www.gyan.devupdated 2026-10-20
- tool
- FFmpeg
- command
- ffmpeg
- flag
- -crf
- default
- 23 for libx264, 28 for libx265
-crf (Constant Rate Factor) tells encoders such as libx264, libx265, libvpx-vp9 and libsvtav1 to target a constant perceived quality and let the bitrate vary. Lower values mean higher quality and bigger files. For libx264 the scale is 0–51 with a default of 23; about 6 steps up halves the file size, 6 steps down doubles it.
Same clip, three CRF values
ffmpeg -hide_banner -loglevel error -f lavfi -i testsrc2=size=640x360:rate=30:duration=5 -pix_fmt yuv420p -c:v rawvideo -y src.nut
for crf in 18 23 28; do
ffmpeg -hide_banner -loglevel error -i src.nut -c:v libx264 -preset medium -crf $crf -y out-$crf.mp4
printf 'crf %s: %s bytes\n' "$crf" "$(stat -c %s out-$crf.mp4)"
doneOutput
crf 18: 741625 bytes crf 23: 500279 bytes crf 28: 271030 bytes
The absolute sizes depend on the content (a synthetic test pattern compresses very well); the ratio between values is what to look at.
Typical ranges
| Encoder | Scale | Default | Usual range |
|---|---|---|---|
| libx264 (H.264) | 0–51 | 23 | 18 (visually near-lossless) to 28 |
| libx265 (HEVC) | 0–51 | 28 | 22 to 32 |
| libvpx-vp9 | 0–63 | — | 15 to 35, with -b:v 0 for constant quality |
| libsvtav1 | 0–63 | — | 20 to 40 |
CRF and preset work together
-preset (ultrafast … veryslow) trades encoding time for compression: at the same CRF, a slower preset gives about the same quality in a smaller file. Pick the slowest preset you can afford, then adjust CRF for quality.
Sources
Related pages
errors · ffmpeglibx264: width not divisible by 2 / height not divisible by 2libx264 rejects odd sizes with yuv420p: width not divisible by 2 (101x101). Scale to even sizes with scale=trunc(iw/2)*2:trunc(ih/2)*2 or use scale=-2:720.compare · ffmpegffmpeg -c copy vs re-encoding: speed, quality and limits-c copy remuxes streams without decoding: fast and lossless, but cuts snap to keyframes and filters are impossible. Re-encoding is slower, lossy, flexible.cheat sheets · ffmpegFFmpeg cheat sheet: convert, cut, scale, extract and inspectFFmpeg cheat sheet: inspect files with ffprobe, change containers, encode H.264, cut without re-encoding, scale, extract audio, make GIFs and thumbnails.