How to Configure libx265 Preset in FFmpeg
This article provides a straightforward guide on how to configure the
preset parameter in FFmpeg’s libx265 encoder. You will
learn what presets are, how they affect encoding speed and compression
efficiency, and the exact commands needed to apply them to your video
processing workflows.
Understanding libx265 Presets
In FFmpeg, the -preset parameter for the
libx265 encoder determines the trade-off between encoding
speed and compression efficiency. A slower preset provides better
compression (smaller file size for the same quality), while a faster
preset encodes the video quickly but results in a larger file size.
The available presets, from fastest to slowest, are:
ultrafastsuperfastveryfastfasterfastmedium(the default preset)slowslowerveryslowplacebo(generally not recommended as it offers negligible quality gains for extremely long encoding times)
Command Syntax
To configure the preset, use the -preset option followed
by the preset name in your FFmpeg command.
Example 1: Fast Encoding (Low CPU Usage)
If you need to encode a video quickly and do not mind a slightly
larger file size, use a faster preset like veryfast:
ffmpeg -i input.mp4 -c:v libx265 -preset veryfast -crf 28 output.mp4Example 2: High Compression (Optimized File Size)
For archival purposes where file size is a priority and you do not
mind waiting longer for the encode to finish, use slow or
veryslow:
ffmpeg -i input.mp4 -c:v libx265 -preset slow -crf 28 output.mp4Recommended Best Practices
- Pair with CRF: Always use the
-presetparameter in conjunction with the-crf(Constant Rate Factor) parameter. Forlibx265, a CRF value between 20 and 28 is recommended. The preset will control how hard the encoder works to pack that target quality into the smallest possible file. - The Sweet Spot: For most general use cases, the
slowpreset offers the best balance between encoding time and compression efficiency. - Hardware Limitations: Avoid
veryslowon older hardware, as HEVC (H.265) encoding is highly CPU-intensive.