How to Configure libx264 Preset in FFmpeg
This article explains how to use the preset parameter in the FFmpeg
libx264 video encoder to balance encoding speed and file
compression. You will learn the syntax for configuring presets, explore
the available preset options from ultrafast to
placebo, and see practical command-line examples to
optimize your video encoding workflow.
Understanding the Preset Parameter
In FFmpeg, the -preset flag for the libx264
encoder determines the trade-off between encoding speed and compression
efficiency. A faster preset will encode video quickly but result in a
larger file size for a given quality level. Conversely, a slower preset
takes more time and processing power to analyze the video, resulting in
a smaller file size at the same quality level.
Available libx264 Presets
The libx264 encoder offers ten standard presets. Ordered
from the fastest (lowest compression efficiency) to the slowest (highest
compression efficiency), they are:
ultrafastsuperfastveryfastfasterfastmedium(the default preset if none is specified)slowslowerveryslowplacebo(generally avoided, as it offers negligible compression gains oververyslowwhile drastically increasing encoding time)
FFmpeg Syntax and Examples
To configure the preset, add the -preset option followed
by the preset name immediately after specifying the libx264
encoder with -c:v libx264.
Example 1: Fast Encoding for Live Streaming or Drafts
If you need to encode a video as quickly as possible and do not mind
a slightly larger file size, use the veryfast or
ultrafast preset:
ffmpeg -i input.mp4 -c:v libx264 -preset veryfast -crf 23 output.mp4Example 2: Optimal Compression for Archiving (Recommended)
For archiving or uploading online where file size and quality are
priorities, the slow or slower preset is
recommended:
ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 22 output.mp4Example 3: Balancing Speed and Quality
If you do not specify a preset, FFmpeg automatically applies the
medium preset. However, you can declare it explicitly:
ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 output.mp4Interaction with CRF (Constant Rate Factor)
When configuring presets, it is best practice to pair them with the
Constant Rate Factor (-crf) parameter for quality control.
The preset controls how hard the encoder works to compress the
video, while the CRF controls the visual quality level
(typically between 18 and 28, where lower means higher quality). Keeping
the same CRF while changing the preset to a slower option will result in
a smaller file size without sacrificing visual quality.