How to Adjust Adaptive Quantization Strength in FFmpeg
This guide explains how to use the -aq-strength
parameter in FFmpeg to adjust adaptive quantization strength during
video encoding. You will learn what adaptive quantization is, how the
strength parameter affects video quality and bitrate distribution, and
the exact commands needed to optimize your video encodes using the
libx264 and libx265 library encoders.
What is Adaptive Quantization (AQ)?
Adaptive Quantization (AQ) is an encoding technique that redistributes bits within a single frame based on complexity. Instead of applying the same compression level to the entire image, AQ shifts bits away from high-complexity, high-motion areas (where human eyes are less likely to notice compression artifacts) and redirects them to flat, low-motion, or gradient areas (such as skies or dark walls) where banding and blocking are highly visible.
Understanding the -aq-strength Parameter
The -aq-strength flag controls how aggressively FFmpeg
redistributes these bits.
- Default Value: The default strength is typically
1.0. - Range: The effective range is generally between
0.0and2.0. - Lower Values (e.g., 0.5 to 0.8): Reduces the bias. This preserves more detail in high-texture or high-motion scenes but may introduce banding or blockiness in flat gradients and dark areas.
- Higher Values (e.g., 1.1 to 1.5): Increases the bias. This cleans up color banding in flat areas and skies but can blur out fine textures in highly detailed areas.
Prerequisite: Setting the AQ Mode
The -aq-strength parameter only works if Adaptive
Quantization is enabled via the -aq-mode option. If
-aq-mode is set to 0 (disabled), changes to
-aq-strength will have no effect.
Common AQ modes for libx264 and libx265
include: * 1 (Variance AQ - default) * 2
(Auto-Variance AQ) * 3 (Biased Variance AQ, optimized for
dark scenes)
How to Use -aq-strength in FFmpeg Commands
To apply these settings, pass the -aq-mode and
-aq-strength flags to your encoder.
Example for libx264 (H.264)
In this example, we set the AQ mode to 1 and increase
the strength slightly to 1.3 to help reduce banding in a
gradient-heavy video:
ffmpeg -i input.mp4 -c:v libx264 -crf 20 -aq-mode 1 -aq-strength 1.3 output.mp4Example for libx265 (HEVC)
For the H.265/HEVC encoder, you must pass these parameters inside the
-x265-params argument:
ffmpeg -i input.mp4 -c:v libx265 -crf 22 -x265-params aq-mode=1:aq-strength=1.2 output.mp4Tips for Tuning AQ Strength
- For Animation and Flat Graphics: Use a slightly
higher strength (e.g.,
1.3to1.5) alongside-aq-mode 1or2to keep flat-colored backgrounds smooth and free of compression blocks. - For High-Detail, Textured Content: If you are
encoding video with highly detailed textures like gravel, foliage, or
water, lower the strength (e.g.,
0.7to0.9) to prevent the encoder from smoothing out those fine details. - For Dark Scenes: Combine
-aq-mode 3(which biases dark frames) with an-aq-strengthof1.0to1.2to eliminate “color banding” in dark, shadowy scenes.