Configure weightp in FFmpeg libx265

This article explains how to configure the weightp (weighted prediction for P-frames) option in the FFmpeg libx265 encoder. You will learn what the different weightp levels mean and how to apply them using the -x265-params flag in your FFmpeg command-line operations to optimize your video compression.

Understanding weightp in x265

The weightp option in the HEVC/H.265 encoder decides how the encoder handles weighted prediction for P-frames (predicted frames). Weighted prediction helps improve compression efficiency and visual quality, particularly during fades, brightness changes, or transitions.

The libx265 encoder supports three values for the weightp parameter:

  • 0 (Disabled): Turns off weighted prediction entirely. Use this if you need to reduce encoding complexity or compatibility issues with specific hardware decoders.
  • 1 (Simple/Blind): Enables weighted reference frames. This is a basic form of weighted prediction with low computational overhead.
  • 2 (Smart): Enables smart weighted prediction. This is the default setting for libx265. It analyzes the video frames to calculate optimal weights, offering the best compression efficiency at the cost of slightly more CPU usage.

How to Configure weightp in FFmpeg

To configure weightp in FFmpeg, you must pass the parameter inside the -x265-params argument. Multiple parameters inside -x265-params are separated by colons (:).

Syntax Structure

ffmpeg -i input.mp4 -c:v libx265 -x265-params weightp=VALUE output.mp4

Examples

Disable weightp (Value: 0) If you want to disable weighted prediction to speed up encoding or for compatibility reasons:

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

Set weightp to Simple (Value: 1) To use basic weighted prediction:

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

Set weightp to Smart (Value: 2 - Default) To explicitly force the highest quality smart estimation (even though it is the default):

ffmpeg -i input.mp4 -c:v libx265 -x265-params weightp=2 output.mp4

Combining weightp with Other Parameters

When encoding with libx265, you will often need to set other parameters like Constant Rate Factor (-crf) or preset speeds alongside weightp. You can chain them together like this:

ffmpeg -i input.mp4 -c:v libx265 -crf 23 -preset medium -x265-params weightp=1:keyint=240 output.mp4

In this command, the -x265-params flag configures both weightp=1 and keyint=240 simultaneously, separated by a colon.