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:
- Target Bitrate (
-b:v): This is the average bitrate the encoder aims to achieve over the duration of the entire video. The encoder will allocate fewer bits to simple, static scenes and more bits to complex, high-motion scenes, keeping the overall average close to this target. - Maximum Bitrate (
-maxrate): This is a strict ceiling that prevents the encoder from exceeding a specific bitrate during highly complex scenes. It is designed to prevent massive bitrate spikes that could cause buffering on networks with limited bandwidth.
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:
- 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.
- 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.
- Buffer Regulation: The
-bufsizeparameter acts as a referee. The encoder calculates how many bits are in this virtual buffer. If a complex scene threatens to exceed the-maxrateover 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
- The encoder tries to achieve the quality of
-crf 31. - If a scene is very simple, the bitrate may drop far below 2 Mbps.
- If a scene is highly complex, the encoder will cap the average
bitrate at 2 Mbps (
-b:v), but allows temporary spikes up to 3 Mbps (-maxrate) within the limits of the 1 Mbps buffer (-bufsize).
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.