How to Configure VP9 Quality in FFmpeg
This article explains how to configure the quality parameters for the
libvpx-vp9 encoder in FFmpeg. It covers the primary rate
control modes—specifically Constant Quality (CRF), Constrained Quality,
and Constant Bitrate (CBR)—along with essential speed and quality CPU
modifiers, enabling you to achieve the optimal balance between file size
and visual fidelity.
1. Constant Quality (Recommended)
For most general encoding tasks, the Constant Rate Factor (CRF) mode is recommended. This mode keeps the visual quality constant throughout the video while varying the bitrate as needed.
To enable pure CRF mode in VP9, you must set the -crf
value and explicitly set the bitrate limit -b:v to
0.
- CRF Range:
0(lossless) to63(worst quality). - Recommended Range:
15to35(typically20to30offers the best balance).
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 output.webm2. Constrained Quality
If you want to maintain a specific quality level but need to ensure the bitrate does not exceed a certain threshold, use Constrained Quality mode. This is useful for streaming scenarios.
To configure this, set your desired -crf value and set
-b:v to your maximum allowed bitrate.
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 2M output.webm3. Constant Bitrate (CBR) / Two-Pass
If your target platform requires a strict, constant target bitrate (e.g., live streaming or strict file-size limitations), use a two-pass approach. In VP9, two-pass encoding is highly recommended over single-pass for bitrate-targeted encodes.
Pass 1:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 1 -f null /dev/null(On Windows, replace /dev/null with
NUL)
Pass 2:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -pass 2 output.webm4. Tuning Encoding Speed and Quality
The libvpx-vp9 encoder has two critical parameters that
dictate how hard the encoder works to compress the video:
-deadline(or-quality): Sets the quality deadline. Options arebest,good, orrealtime.goodis the default and recommended for most encodes.bestprovides marginal quality improvements at the cost of significantly longer encode times.
-cpu-used: Sets the quality/speed trade-off.- Range:
0to8(when using-deadline goodorrealtime). - Lower numbers (e.g.,
0,1,2) mean slower encoding but higher quality per megabyte. - Higher numbers (e.g.,
4,5) mean faster encoding but lower visual quality. The recommended value for a good speed/quality balance is-cpu-used 1or-cpu-used 2.
- Range:
Example of an optimized, high-quality encode command:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 23 -b:v 0 -deadline good -cpu-used 1 -c:a libopus -b:a 128k output.webm