How to Configure weightb in FFmpeg libx265

This article explains how to configure the weightb (weighted prediction for B-frames) option in the FFmpeg libx265 encoder. You will learn what this setting does, how it impacts video compression quality, and how to properly apply it in your FFmpeg command-line workflows with clear syntax examples.

Understanding weightb in libx265

In H.265/HEVC video encoding, B-frames (bi-predictive frames) refer to both past and future frames to compress video data efficiently. The weightb option enables or disables weighted prediction for these B-frames.

Weighted prediction allows the encoder to scale the reference frame’s pixel values, which significantly improves compression efficiency and visual quality in scenes containing fades, dissolves, or gradual illumination changes (like camera flashes or shadows).

By default, weightb is enabled (weightb=1) in most libx265 presets because it offers a solid compression advantage with minimal encoding overhead.

FFmpeg Command Syntax

In FFmpeg, options specific to the libx265 encoder are passed using the -x265-params flag. Multiple parameters within this flag are separated by colons (:).

How to Enable weightb

To explicitly enable weighted prediction for B-frames, set weightb=1 inside the -x265-params argument:

ffmpeg -i input.mp4 -c:v libx265 -x265-params weightb=1 output.mp4

How to Disable weightb

To disable weighted B-frames (which may be useful for hardware compatibility issues or specific low-latency streaming profiles), set weightb=0:

ffmpeg -i input.mp4 -c:v libx265 -x265-params weightb=0 output.mp4

Combining weightb with Other Parameters

When configuring your encoder, you will often need to define multiple parameters. Here is how to combine weightb with other common libx265 settings such as CRF (Constant Rate Factor) and keyframe intervals:

ffmpeg -i input.mp4 -c:v libx265 -crf 23 -x265-params weightb=0:keyint=240:ref=4 output.mp4

In this command, weightb=0 is used alongside keyint=240 and ref=4, with each parameter separated by a colon.