How to Configure weightp in FFmpeg libx264
This article provides a straightforward guide on how to configure the
weightp (Weighted Prediction for P-frames) option in the
FFmpeg libx264 encoder. You will learn what the
weightp parameter does, the available configuration values,
and the exact FFmpeg command-line syntax required to apply these
settings to your video encoding pipeline.
Understanding weightp in libx264
The weightp option controls how the libx264
encoder handles weighted prediction for P-frames (predictive frames).
Weighted prediction improves compression efficiency and video quality,
particularly during fades, flashes, or luminance transitions, by scaling
the reference frames.
There are three configuration levels available for
weightp:
0(Disabled): Turns off weighted prediction entirely. Use this if you need maximum compatibility with older or highly restricted hardware decoders.1(Blind): Enables blind references. This is a simpler, faster method of weighted prediction that has a low performance cost but offers fewer quality improvements.2(Smart): Enables smart reference analysis. This method analyzes the video frames to calculate the best weights. It offers the highest compression efficiency and visual quality, and is the default setting for most standard x264 presets (exceptultrafast).
FFmpeg Command Syntax
To configure weightp in FFmpeg, you must pass the option
through the -x264-params flag. Multiple parameters inside
-x264-params are separated by colons (:).
Example 1: Disabling weightp (Value: 0)
To disable weighted prediction completely for maximum hardware compatibility:
ffmpeg -i input.mp4 -c:v libx264 -x264-params weightp=0 output.mp4Example 2: Setting weightp to Smart (Value: 2)
To force the highest-quality smart weighted prediction (useful if you are using a fast preset that disables it by default):
ffmpeg -i input.mp4 -c:v libx264 -preset superfast -x264-params weightp=2 output.mp4Example 3: Combining with Other x264 Parameters
If you need to define multiple x264 parameters, append them inside
the -x264-params argument using a colon:
ffmpeg -i input.mp4 -c:v libx264 -x264-params weightp=2:keyint=24:ref=4 output.mp4Alternative Syntax: -x264opts
You can also use the older -x264opts syntax, where
options are separated by colons:
ffmpeg -i input.mp4 -c:v libx264 -x264opts weightp=2 output.mp4Using -x264-params is the recommended modern approach
for configuring x264-specific library settings in FFmpeg.