Configure Adaptive B-Frame Placement in FFmpeg

This article explains how to configure adaptive B-frame placement in FFmpeg using the -b_strategy option. You will learn how adaptive B-frame decisions impact video compression efficiency, the differences between the available strategy settings, and how to implement these settings in your command-line workflows to balance encoding speed and visual quality.

Understanding B-Frames and Adaptive Placement

B-frames (bidirectional predictive frames) achieve high compression by referencing both past and future frames. While increasing the number of B-frames generally reduces file size, inserting them blindly during high-motion scenes can degrade video quality.

Adaptive B-frame placement solves this by analyzing the video content and dynamically deciding whether a B-frame or a P-frame is more efficient for any given scene. In FFmpeg, this behavior is controlled using the -b_strategy option, which works in tandem with the -bf option (which sets the maximum number of consecutive B-frames allowed).

The -b_strategy Settings

The -b_strategy option accepts three primary integer values, each offering a different trade-off between encoding speed and compression efficiency:

Command Examples

To use -b_strategy, you must also define the maximum consecutive B-frames using the -bf flag. If -bf is set to 0, -b_strategy will have no effect.

Example 1: Standard Balanced Encoding (Default)

This configuration allows up to 3 consecutive B-frames and uses the fast adaptive strategy. It is ideal for general streaming and everyday encoding.

ffmpeg -i input.mp4 -c:v libx264 -bf 3 -b_strategy 1 output.mp4

Example 2: Maximum Quality and Compression (Archival)

This configuration allows up to 16 consecutive B-frames and uses the optimal adaptive strategy. This is best for archiving videos where encoding time is not a concern, but file size and quality are.

ffmpeg -i input.mp4 -c:v libx264 -bf 16 -b_strategy 2 output.mp4

Example 3: Fast Constant GOP Encoding

This disables adaptive placement, forcing the encoder to strictly use exactly 2 B-frames between anchor frames. This is useful for hardware compatibility testing or low-latency streaming where encoding speed must be maximized.

ffmpeg -i input.mp4 -c:v libx264 -bf 2 -b_strategy 0 output.mp4