How to Set libvpx Bitrate in FFmpeg

This article provides a quick guide on how to configure the target bitrate for the WebM VP8 and VP9 video codecs using the libvpx and libvpx-vp9 encoders in FFmpeg. You will learn the exact command-line arguments needed to control bitrate using Constant Bitrate (CBR), Variable Bitrate (VBR), and Constrained Quality modes.

The Basic Bitrate Argument

In FFmpeg, the target video bitrate for any encoder, including libvpx (for VP8) and libvpx-vp9 (for VP9), is set using the -b:v flag.

The basic syntax is:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M output.webm

In this command: * -c:v libvpx-vp9 selects the VP9 encoder (use libvpx for VP8). * -b:v 2M sets the target video bitrate to 2 Megabits per second (Mbps). You can also use k for kilobits (e.g., -b:v 1500k).


Depending on your project requirements, you should configure the bitrate using one of the three modes below.

For the best quality-to-file-size ratio, you should use a Constant Rate Factor (CRF) and set the target bitrate to 0. This forces the encoder to focus entirely on quality.

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

2. Constrained Quality (Target Maximum Bitrate)

If you want to maintain a specific quality level but cap the maximum bandwidth used by the video, combine the -crf flag with a maximum bitrate limit.

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

In this mode, the encoder will target the quality of CRF 30, but the bitrate will not be allowed to exceed 2 Mbps.

3. Constant Bitrate (CBR)

If you are streaming video or need a strict, predictable file size, you must enforce Constant Bitrate. To do this, set -b:v, -minrate, and -maxrate to the same value.

ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M -minrate 2M -maxrate 2M output.webm

For VP8 (libvpx), you should also add the -quality fixed argument when forcing CBR.