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:
0(Disabled / Constant): The encoder disables adaptive placement. It will always insert the maximum number of consecutive B-frames specified by the-bfflag, regardless of scene content. This is the fastest method but results in lower compression efficiency and potential visual artifacts in high-motion scenes.1(Fast Adaptive): The encoder uses a fast, heuristic-based algorithm to decide when to use B-frames. This is typically the default setting for encoders likelibx264andlibx265. It offers a great balance, providing most of the quality benefits of adaptive placement with minimal impact on encoding speed.2(Device / Optimal Adaptive): The encoder uses a high-quality, lookahead-based algorithm that evaluates multiple frame path possibilities to determine the mathematically optimal placement of B-frames. This option yields the highest visual quality and best compression ratio but significantly slows down the encoding process.
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.mp4Example 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.mp4Example 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