Set Min and Max Quantizer for libvpx in FFmpeg
This article explains how to configure the minimum and maximum
quantizer limits when using the libvpx (VP8) and
libvpx-vp9 (VP9) encoders in FFmpeg. Controlling these
parameters allows you to restrict the quality range of your output
video, preventing the encoder from producing excessively high-bitrate
peaks or dropping the quality below an acceptable threshold.
To configure the minimum and maximum quantizers in FFmpeg, you use
the -qmin and -qmax flags. For both VP8 and
VP9, the quantizer scale ranges from 0 to 63, where 0
represents lossless/best quality (largest file size) and 63 represents
the lowest quality (smallest file size).
Basic Command Syntax
You can apply these limits by adding the -qmin and
-qmax options directly to your FFmpeg command.
For VP9 (libvpx-vp9):
ffmpeg -i input.mp4 -c:v libvpx-vp9 -qmin 10 -qmax 42 output.webmFor VP8 (libvpx):
ffmpeg -i input.mp4 -c:v libvpx -qmin 10 -qmax 42 output.webmParameter Breakdown
-qmin <value>: Sets the minimum quantizer limit (integer from 0 to 63). A lower value (e.g.,10or0) allows the encoder to use higher quality for scenes that require it, though it can lead to bitrate spikes.-qmax <value>: Sets the maximum quantizer limit (integer from 0 to 63). A higher value (e.g.,50or63) allows the encoder to degrade quality to stay within bitrate limits during complex scenes. Lowering this value (e.g., to40) prevents the video from looking too blocky or distorted during high-motion scenes.
Using Quantizer Limits with Constant Quality (CRF) Mode
When using the Constant Rate Factor (-crf) mode, the
quantizer bounds act as safety thresholds. For example, if you target a
quality level of 30, you can use -qmin and
-qmax to ensure the encoder never goes outside your desired
quality boundaries:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -qmin 15 -qmax 40 output.webmIn this setup, FFmpeg targets a quality level of 30 but is strictly forbidden from using a quantizer lower than 15 (preventing wasted bandwidth on static scenes) or higher than 40 (preventing excessive compression artifacts in highly dynamic scenes).