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:

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