Configure AQ Strength in FFmpeg libx265

This article explains how to configure the adaptive quantization (AQ) strength in the FFmpeg libx265 encoder. You will learn about the essential parameters involved—specifically aq-mode and aq-strength—how they influence video quality, and how to apply them using practical FFmpeg command-line examples.

Understanding Adaptive Quantization in x265

Adaptive Quantization (AQ) is a feature in the H.265/HEVC encoder that redistributes bits within a single video frame. Without AQ, the encoder tends to spend too many bits on complex, high-detail areas (where compression artifacts are hard to see) and too few bits on flat, low-detail areas like skies or dark walls (where blocking and banding artifacts are highly visible).

By adjusting the AQ mode and strength, you can instruct libx265 to shift bit allocation to flatter or darker areas, drastically improving perceived visual quality.

Key Parameters for AQ Configuration

In FFmpeg, HEVC-specific parameters are passed directly to the libx265 encoder using the -x265-params flag. To configure AQ, you need to set two main arguments: aq-mode and aq-strength.

1. aq-mode (Adaptive Quantization Mode)

This parameter determines how the encoder analyzes the frame to distribute bits. * 0 (Disabled): No adaptive quantization is applied. * 1 (AQ Enabled): Spreads bits across the frame to prevent banding and blocking in flat areas. * 2 (Auto-Variance AQ): Automatically adjusts strength based on the variance of block complexity within the frame. This is the default mode. * 3 (Auto-Variance AQ with Bias for Dark Scenes): An extension of mode 2 that biases bit allocation toward dark areas. This is highly recommended for cinematic content to prevent color banding in shadows.

2. aq-strength (Adaptive Quantization Strength)

This parameter controls the intensity of the AQ mode. * Range: Typically 0.0 to 3.0 (Default is 1.0). * Lower values (e.g., 0.5 to 0.8): Restricts bit redistribution. Use this if you notice too many bits being wasted on flat surfaces at the expense of high-detail textures. * Higher values (e.g., 1.1 to 1.5): Increases bit redistribution to flat and dark areas. Use this if you see noticeable banding or blockiness in gradients, skies, or dark scenes.


FFmpeg Command Examples

To apply these settings in FFmpeg, combine them within the -x265-params option, separating multiple parameters with colons (:).

Example 1: Standard Optimization (Default Profile)

This command uses Auto-Variance AQ (Mode 2) with a slightly elevated strength of 1.2 to help eliminate blocking in flat areas.

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

This command uses AQ Mode 3 (dark-bias) with a strength of 1.1. This is ideal for movies, anime, or gaming content containing dark environments and gradients.

ffmpeg -i input.mp4 -c:v libx265 -crf 20 -x265-params aq-mode=3:aq-strength=1.1 output.mp4

Example 3: Low AQ Strength for High-Detail Preservation

If you are encoding at a high bitrate/low CRF and want to ensure that fine textures (like film grain or hair) are not blurred, you can lower the strength:

ffmpeg -i input.mp4 -c:v libx265 -crf 18 -x265-params aq-mode=2:aq-strength=0.7 output.mp4