Configure FFmpeg libx265 Adaptive Quantization

Adaptive Quantization (AQ) in the libx265 encoder is a critical feature that improves visual quality by distributing bits more effectively across different parts of a video frame, preventing blockiness in flat areas and gradient banding. This article provides a straightforward guide on how to configure the AQ mode and its strength in FFmpeg using the libx265 encoder parameters to optimize your HEVC/H.265 encodes.

Understanding the AQ Parameters

To configure Adaptive Quantization in libx265, you must pass specific parameters to the encoder using the -x265-params flag in your FFmpeg command. The two primary parameters are aq-mode and aq-strength.

1. AQ Mode (aq-mode)

The aq-mode parameter determines how the encoder distributes bits across different regions of a frame. You can choose from five different modes:

2. AQ Strength (aq-strength)

The aq-strength parameter adjusts the intensity of the chosen AQ mode. * Range: 0.0 to 3.0 * Default: 1.0 * A lower value (e.g., 0.8) reduces the effect of AQ, while a higher value (e.g., 1.2 to 1.5) increases the bit distribution variance, which can help eliminate banding in problematic videos but may increase the overall file size.


How to Configure AQ in the FFmpeg Command

To apply these settings, define them inside the -x265-params argument, separating multiple parameters with colons (:).

Basic Command Example

The following command encodes a video using libx265 with AQ Mode 3 (biased to dark scenes) and an AQ Strength of 1.2:

ffmpeg -i input.mp4 -c:v libx265 -crf 22 -x265-params aq-mode=3:aq-strength=1.2 -c:a copy output.mp4

Configuration Recommendations

Depending on your source material, use the following configurations for optimal results: