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.

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.

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 output.webm

2. 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.webm

3. 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.webm

4. Tuning Encoding Speed and Quality

The libvpx-vp9 encoder has two critical parameters that dictate how hard the encoder works to compress the video:

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