How to Configure CRF in FFmpeg libx265
This article explains how to configure the Constant Rate Factor (CRF)
value for the libx265 (H.265/HEVC) encoder in FFmpeg. It
covers the exact command-line syntax, the default CRF settings, the
recommended range for balancing quality and file size, and practical
examples to help you optimize your video encoding workflow.
The CRF Parameter for libx265
Constant Rate Factor (CRF) is the default quality-setting mode for
the libx265 encoder. It scales the file size and bitrate to
maintain a visually consistent level of quality throughout the entire
video.
To set the CRF value in FFmpeg, use the -crf option
followed by your chosen numerical value.
ffmpeg -i input.mp4 -c:v libx265 -crf 23 output.mp4Understanding CRF Values for H.265
The CRF scale for libx265 ranges from 0 to
51: * 0: Lossless compression (very large file
sizes). * 51: Worst possible quality.
Unlike the H.264 (libx264) encoder, which has a default
CRF of 23, the default CRF for the H.265 (libx265) encoder
is 28. Because H.265 is significantly more efficient
than H.264, a higher CRF value in H.265 yields a subjectively similar
visual quality to a lower CRF value in H.264, but at a much lower
bitrate.
Recommended Range
For most general encoding tasks, the recommended CRF range is 20 to 28: * CRF 18–21: High quality, visually near-lossless. Best for archiving or high-end streaming. * CRF 22–25: Excellent balance between visual quality and file size. * CRF 26–28: Good quality with highly optimized, smaller file sizes. Ideal for web distribution.
Every decrease of 6 units in the CRF value roughly doubles the bitrate, while an increase of 6 units halves it.
Combining CRF with Presets
When configuring the CRF in libx265, you should always
pair it with the -preset option. The preset determines the
encoding speed-to-compression ratio.
The available presets are: ultrafast,
superfast, veryfast, faster,
fast, medium (default), slow,
slower, and veryslow.
Using a slower preset allows the encoder to use more advanced compression algorithms, resulting in a smaller file size for the exact same CRF quality level.
Example: High-Quality Slow Encode
This command uses a CRF of 22 and the slow preset to
achieve high-quality output with an optimized file size:
ffmpeg -i input.mov -c:v libx265 -crf 22 -preset slow -c:a copy output.mp4