libvpx Target Bitrate vs Max Bitrate Explained

This article explains the relationship between target bitrate (-b:v) and maximum bitrate (-maxrate) in the libvpx (VP8/VP9) video encoder. You will learn how these two settings interact during Constrained Quality (CQ) and Variable Bitrate (VBR) encoding to control video quality, manage bandwidth limits, and prevent playback buffering.

The Core Definitions

To understand how these two parameters interact, it is essential to first define their individual roles in the libvpx encoder:

How Target and Max Bitrate Work Together

When you use both -b:v and -maxrate together, you are employing a rate-control method known as Constrained VBR (Variable Bitrate) or VBV (Video Buffer Verifier) compliance. This combination requires a third parameter to function correctly: the buffer size (-bufsize).

The relationship between these settings determines how the encoder behaves:

  1. The Allowance for Spikes: The difference between the target bitrate and the maximum bitrate defines how much flexibility the encoder has. If your target is 2 Mbps and your maxrate is 4 Mbps, the encoder can double the allocation of bits for highly complex scenes (like explosions or fast panning) to maintain quality, as long as the overall average remains around 2 Mbps.
  2. Strictness of Control: If the maximum bitrate is set too close to the target bitrate (e.g., target of 3 Mbps and maxrate of 3.2 Mbps), the encoder behaves almost like a Constant Bitrate (CBR) encoder. This limits quality in complex scenes because the encoder cannot allocate extra bits when needed.
  3. Buffer Regulation: The -bufsize parameter acts as a referee. The encoder calculates how many bits are in this virtual buffer. If a complex scene threatens to exceed the -maxrate over the window of the -bufsize, the encoder will aggressively degrade the video quality of those frames to stay under the limit.

Application in VP9 Constrained Quality (CQ) Mode

In VP9, a popular encoding method is Constrained Quality (CQ) mode. In this mode, you set a target quality level using the Constant Rate Factor (-crf), and use -b:v as a maximum cap, often alongside -maxrate.

For example, when using the following FFmpeg command: ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 31 -b:v 2M -maxrate 3M -bufsize 1M output.webm

Understanding this relationship allows you to optimize video files for streaming platforms, ensuring the highest possible visual quality while guaranteeing the stream will not exceed the bandwidth limits of your viewers.