How to Configure Min and Max Quantizer in libaom?

Configuring the minimum and maximum quantizer bounds allows video engineers to maintain precise control over video quality and file sizes during AV1 encoding. This article provides a comprehensive overview of how to set these limits using the native aomenc command-line utility, FFmpeg’s libaom-av1 wrapper, and direct C API integrations.

Understanding Quantizer Bounds in AV1

In the AV1 codec architecture, the quantizer parameter (often called qindex) dictates the compression level applied to the video frames. The values range strictly from 0 to 63, where:

By capping these values, you prevent the encoder from producing overly bloated files during complex scenes (by setting a minimum q) or generating unwatchable, heavily pixelated frames during high-motion sequences (by setting a maximum q).

Method 1: Using the Native aomenc CLI

If you are encoding directly with the standalone Alliance for Open Media reference encoder (aomenc), the parameters are defined explicitly using explicit quantizer flags.

aomenc --end-usage=vbr --target-bitrate=2000 --min-q=15 --max-q=45 -o output.webm input.y4m

In this scenario, aomenc will adjust the bitrate targets but will never use a quality index sharper than 15 or more degraded than 45.

Method 2: Encoding via FFmpeg (libaom-av1)

When using FFmpeg with the libaom-av1 library wrapper, the options inherit generic FFmpeg codec properties. You configure the boundaries using the standard -qmin and -qmax flags.

ffmpeg -i input.mp4 -c:v libaom-av1 -b:v 2M -qmin 18 -qmax 40 output.mkv

Alternatively, you can pass these parameters directly to the underlying library through the -aom-params global mapping flag:

ffmpeg -i input.mp4 -c:v libaom-av1 -b:v 2M -aom-params min-q=18:max-q=40 output.mkv

Method 3: Programmatic Configuration via C API

For software applications integrating the libaom library natively, configuring the quantizer range requires altering the encoder configuration structure (aom_codec_enc_cfg_t) before initializing the codec context.

The configuration fields responsible for boundary control are rc_min_quantizer and rc_max_quantizer.

#include <aom/aom_encoder.h>
#include <aom/aomcx.h>

aom_codec_enc_cfg_t cfg;
aom_codec_enc_config_default(aom_codec_av1_cx(), &cfg, 0);

// Restrict the quantizer scale between 20 and 50
cfg.rc_min_quantizer = 20;
cfg.rc_max_quantizer = 50;

// Initialize the encoder context with the modified configuration struct
aom_codec_ctx_t codec;
aom_codec_enc_init(&codec, aom_codec_av1_cx(), &cfg, 0);

Best Practices for Rate Control

When pairing quantizer limits with different rate control modes, keep the following interactions in mind:

Rate Control Mode Recommended Usage
VBR / CBR Highly recommended. Setting a -qmax acts as a safety valve to ensure quality does not drop below your threshold during spike scenes.
CQ (Constrained Quality) Useful to provide a strict cap if the target -crf behaves unpredictably on specific source material.
Pure CRF Generally redundant, as the Constant Rate Factor explicitly sets the target quality index natively.