Configure libx265 Deblocking Filter in FFmpeg

Optimizing video quality in HEVC encoding often requires fine-tuning the in-loop deblocking filter. This guide provides a straightforward explanation of how to configure the deblocking filter options in the libx265 encoder using FFmpeg, including the command-line syntax, parameter values, and practical examples for different encoding scenarios.

In the HEVC (H.265) standard, the deblocking filter is an in-loop process designed to smooth out blocky artifacts along block boundaries. In FFmpeg, these settings are modified by passing specific arguments to the libx265 encoder via the -x265-params flag.

The syntax for configuring the deblocking filter is:

-x265-params deblock=<tcOffset>:<betaOffset>

Both tcOffset (which controls the threshold for applying the filter) and betaOffset (which controls the strength of the filter) accept integer values between -6 and 6. The default setting is 0:0.

Common Configuration Examples

To preserve high-frequency details (ideal for high-quality, high-bitrate encodes), you should lower the deblocking strength. A popular setting is -1:-1 or -2:-2:

ffmpeg -i input.mp4 -c:v libx265 -crf 20 -x265-params deblock=-1:-1 output.mp4

For low-bitrate encodes where blocking artifacts are highly visible, you can increase the deblocking strength to smooth out the image. A setting of 1:1 or 2:2 is recommended:

ffmpeg -i input.mp4 -c:v libx265 -crf 28 -x265-params deblock=1:1 output.mp4

If you want to disable the deblocking filter entirely to keep the source as sharp as possible (though this may introduce blockiness), use the no-deblock parameter:

ffmpeg -i input.mp4 -c:v libx265 -x265-params no-deblock=1 output.mp4

When combining the deblocking filter with other libx265 parameters, separate each option with a colon inside the -x265-params string:

ffmpeg -i input.mp4 -c:v libx265 -x265-params deblock=-1:-1:aq-mode=3:no-sao=1 output.mp4