Configure B-Frame Strategy in FFmpeg libx265

This article explains how to configure the B-frame decision strategy in the FFmpeg libx265 HEVC encoder. You will learn about the different B-frame adaptation modes, how they impact encoding speed and video quality, and the exact FFmpeg command-line arguments required to apply these settings to your video transcode workflow.

Understanding the B-Frame Strategy (b-adapt)

In the H.265/HEVC encoder libx265, the B-frame strategy determines how the encoder decides whether to use a P-frame or a B-frame at any given point in the video sequence. This decision is controlled by the b-adapt parameter.

There are three primary settings for the B-frame strategy:

  • 0 (None / Disabled): The encoder bypasses adaptive B-frame placement and strictly writes the maximum number of allowed B-frames. This is the fastest setting but results in the lowest compression efficiency.
  • 1 (Fast): The encoder uses a fast, heuristic-based decision algorithm. It offers a good balance between encoding speed and compression quality.
  • 2 (Optimal / Full): The encoder performs a full, trellis-like lookahead decision. This is the slowest option but yields the highest quality and best compression efficiency. This is the default setting for most presets.

Setting the B-Frame Strategy in FFmpeg

To configure the B-frame strategy in FFmpeg, you pass the b-adapt option inside the -x265-params flag. Additionally, you should define the maximum number of consecutive B-frames allowed using the bframes parameter (or the standard -bf FFmpeg flag).

The most reliable way to pass encoder-specific parameters to libx265 is by using the -x265-params argument, separating multiple settings with colons.

Example: Setting Optimal B-Frame Strategy (b-adapt=2) with 4 B-frames:

ffmpeg -i input.mp4 -c:v libx265 -x265-params b-adapt=2:bframes=4 -crf 22 output.mp4

Example: Setting Fast B-Frame Strategy (b-adapt=1) for faster encoding:

ffmpeg -i input.mp4 -c:v libx265 -x265-params b-adapt=1:bframes=3 -crf 22 output.mp4

Method 2: Using Native FFmpeg Flags

Alternatively, you can use the native FFmpeg -b_strategy flag, though it maps directly to b-adapt under the hood.

ffmpeg -i input.mp4 -c:v libx265 -b_strategy 2 -bf 4 -crf 22 output.mp4

Performance vs. Quality Trade-Off

  • Use b-adapt=2 for archival, distribution, or high-quality streaming where encoding time is not a constraint.
  • Use b-adapt=1 for live streaming, fast turnaround drafts, or when encoding on lower-end hardware where CPU resources are limited.
  • Avoid b-adapt=0 unless you have a highly specific compatibility constraint, as it significantly degrades compression efficiency.