How to Set VP9 Min and Max Quantizer in FFmpeg
Controlling the video quality and bitrate in FFmpeg when using the
VP9 codec (libvpx-vp9) often requires restricting the
quantizer range. This article provides a straightforward guide on how to
configure the minimum and maximum quantizer limits using the
-qmin and -qmax flags to optimize your
encoding balance between file size and visual fidelity.
Understanding VP9 Quantizers
In VP9 encoding, the quantizer scale determines how much detail is discarded to save space. The VP9 quantizer scale ranges from 0 to 63: * 0 represents the highest quality (lossless, or near-lossless depending on profile settings). * 63 represents the lowest quality and highest compression.
By default, FFmpeg allows the encoder to freely choose any quantizer
within this 0–63 range to meet target bitrates. By setting a minimum
(-qmin) and maximum (-qmax) limit, you prevent
the encoder from making the video too low-quality during complex scenes,
or wasting bitrate on simple scenes.
Command Line Syntax
To configure these limits, pass the -qmin and
-qmax options directly after specifying the
libvpx-vp9 encoder.
Here is a basic example of constrained bitrate encoding with quantizer limits:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -qmin 10 -qmax 42 output.webmIn this command: * -c:v libvpx-vp9: Selects the VP9
encoder. * -b:v 2M: Sets a target bitrate of 2 Mbps. *
-qmin 10: Prevents the quantizer from dropping below 10
(capping maximum quality to avoid wasted bits). * -qmax 42:
Prevents the quantizer from rising above 42 (ensuring the video quality
does not degrade past a certain threshold).
Using Quantizer Limits with CRF (Recommended)
When using Constant Rate Factor (CRF) mode—the recommended method for
one-pass VP9 encoding—you can still use -qmin and
-qmax to act as safety boundaries.
To use CRF with quantizer limits, you must set the bitrate option
-b:v to 0:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -qmin 15 -qmax 40 output.webm-crf 30: Targets a base quality level of 30.-b:v 0: Required to enable pure CRF mode inlibvpx-vp9.-qmin 15and-qmax 40: Restricts the fluctuation of the encoder’s internal quantizer selection to stay strictly between 15 and 40.
Recommended Values for General Use
- High Quality / Archival: Set
-qmin 0and-qmax 30. - Standard Web Distribution: Set
-qmin 15and-qmax 45. - Low Bitrate / Streaming: Set
-qmin 20and-qmax 50.