FFmpeg -b:v vs -maxrate Difference Explained

This article explains how FFmpeg handles the -b:v and -maxrate options during video encoding. It clarifies the operational differences between setting an average target video bitrate versus capping the peak encoding rate, demonstrating how these settings interact to control video quality and file size, especially when streaming.

The Role of -b:v (Target Bitrate)

The -b:v option sets the target or average video bitrate for the encoder. When you specify -b:v 2M, you are instructing FFmpeg to aim for an average bitrate of 2 Megabits per second across the duration of the entire video.

During encoding, the library (such as libx264) allocates more data to complex, high-motion scenes and less data to simple, static scenes. The overall goal of the encoder when using -b:v alone is to hit the specified average by the end of the file, meaning individual segments of the video may temporarily spike far above or drop far below this target.

The Role of -maxrate (Maximum Bitrate Limit)

The -maxrate option defines a strict ceiling for the video bitrate. Unlike -b:v, which acts as a flexible target, -maxrate prevents the encoder from exceeding a specific bitrate during highly complex scenes.

By itself, -maxrate does nothing. For the encoder to enforce this maximum limit, it must be paired with the -bufsize (buffer size) option. The buffer size tells the encoder how often to calculate the average bitrate and check if it is exceeding the -maxrate.

How They Work Together: Constrained Bitrate (VBV)

When you combine -b:v, -maxrate, and -bufsize, you enable Constrained Variable Bitrate (CVBR) encoding, often referred to as the Video Buffer Verifier (VBV) model.

For example, using the command: ffmpeg -i input.mp4 -b:v 2M -maxrate 3M -bufsize 6M output.mp4

In this scenario: * -b:v 2M tells the encoder to try and maintain an overall average of 2 Mbps. * -maxrate 3M prevents the encoder from ever spiking above 3 Mbps. * -bufsize 6M sets a 6 Megabit receiver buffer. The encoder will check the bitrate over this buffer window to ensure the 3 Mbps limit is never violated.

Why the Difference Matters

Using only -b:v is ideal for local file playback and progressive downloads where temporary bitrate spikes do not cause playback issues.

Using -b:v in conjunction with -maxrate and -bufsize is essential for network streaming (such as HLS, DASH, or live streaming to platforms like Twitch and YouTube). Streaming clients have limited network bandwidth and physical buffer sizes. Without -maxrate, a sudden high-motion scene could produce a massive bitrate spike that exceeds the viewer’s internet speed, resulting in playback buffering and stuttering.