FFmpeg libvpx-vp9 Rate Control Modes
This article provides a comprehensive overview of the different rate
control modes supported by the FFmpeg libvpx-vp9 encoder.
You will learn how to configure Constant Quality (CRF), Constrained
Quality, Variable Bitrate (VBR), Constant Bitrate (CBR), and Lossless
encoding modes, along with the specific FFmpeg commands and use cases
for each.
1. Constant Quality (CRF)
The Constant Rate Factor (CRF) mode is the recommended choice for file-based video encoding when you want to ensure a consistent level of visual quality throughout the video, regardless of the motion or complexity of the scenes.
To enable true CRF mode in libvpx-vp9, you must set the
video bitrate limit (-b:v) to 0. The quality
scale for VP9 ranges from 0 (best quality, largest file
size) to 63 (lowest quality, smallest file size), with
15 to 35 being the recommended range for most
web videos.
Example Command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 output.webm2. Constrained Quality (CQ)
Constrained Quality mode allows you to target a specific quality level (using CRF) while enforcing a maximum bitrate ceiling. This prevents bitrate spikes in high-motion scenes that might exceed your streaming bandwidth or storage limitations.
This mode is activated by setting both a -crf value and
a non-zero -b:v value. The encoder will attempt to encode
at the requested CRF but will cap the bitrate at the specified target if
a scene is too complex.
Example Command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 2000k output.webm3. Two-Pass Variable Bitrate (VBR)
Variable Bitrate mode is ideal when you need to hit a specific target file size or average bitrate. It requires a two-pass process to optimize quality distribution: the first pass analyzes the video to identify complex scenes, and the second pass performs the actual encoding based on that analysis.
Example Commands:
# Pass 1
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 1 -f null /dev/null
# Pass 2
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 2 output.webm4. Constant Bitrate (CBR)
Constant Bitrate mode keeps the output bitrate highly stable. It is primarily used for live streaming where network bandwidth is strictly limited and cannot accommodate bitrate fluctuations.
To force libvpx-vp9 into CBR mode, you must set the
target, minimum, and maximum bitrates to the same value, and pair them
with the -quality realtime and -speed settings
to optimize the encoder for live encoding.
Example Command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 1000k -minrate 1000k -maxrate 1000k -quality realtime -speed 5 output.webm5. Lossless Encoding
Lossless mode compresses the video without discarding any visual data, resulting in a perfect mathematical copy of the source video. This mode is useful for archiving high-value source footage, video editing intermediates, or master files.
To enable lossless encoding in VP9, use the -lossless 1
flag.
Example Command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -lossless 1 output.webm