How to Set B-Frame Bias in FFmpeg libx265
This article explains how to configure the B-frame bias in the FFmpeg
libx265 encoder. You will learn the specific command-line
parameters required to adjust B-frame decision-making, understand how
different bias values affect video compression and quality, and view
practical command examples to implement in your encoding workflow.
To configure the B-frame bias in libx265, you must use
the -x265-params option in FFmpeg to pass the
b-bias argument directly to the underlying x265
encoder.
Understanding B-Frame Bias
B-frames (bi-predictive pictures) are highly compressed frames that refer to both preceding and succeeding frames. The B-frame bias setting controls how aggressively the encoder chooses to use B-frames over P-frames (predictive frames).
- The Range: The
b-biasvalue ranges from -100 to 100. - Default Value: The default value is 0.
- Positive Values (e.g., 20 to 100): These bias the encoder toward using more B-frames. Because B-frames are more compressed, this can decrease the overall file size, but setting it too high may degrade visual quality.
- Negative Values (e.g., -20 to -100): These bias the encoder toward using fewer B-frames, favoring P-frames instead. This can improve image quality in complex scenes but will increase the overall file size.
FFmpeg Command Syntax
To set the B-frame bias, append b-bias=value to the
-x265-params flag.
Example 1: Increasing B-Frame Usage
To encourage the encoder to use more B-frames for better compression:
ffmpeg -i input.mp4 -c:v libx265 -x265-params b-bias=30 output.mp4Example 2: Decreasing B-Frame Usage
To discourage the encoder from using B-frames to preserve high-motion detail:
ffmpeg -i input.mp4 -c:v libx265 -x265-params b-bias=-20 output.mp4Combining with Maximum B-Frames
The B-frame bias works in tandem with the maximum allowed number of
B-frames. If the maximum number of B-frames is set to 0, B-frame bias
will have no effect. You can define both the maximum B-frames
(bframes) and the bias (b-bias) together
inside the -x265-params option by separating them with a
colon:
ffmpeg -i input.mp4 -c:v libx265 -x265-params bframes=6:b-bias=15 output.mp4