How to Configure FFmpeg ip_ratio and pb_ratio
This article explains how to configure the -ip_ratio and
-pb_ratio parameters in FFmpeg to optimize video encoding
quality and compression. You will learn what these ratios represent, how
they impact I-frame, P-frame, and B-frame quality, and how to apply them
using practical command-line examples.
Understanding the Parameters
In video compression, frames are divided into three main types: I-frames (intra-coded, full images), P-frames (predicted from previous frames), and B-frames (bi-directionally predicted).
The -ip_ratio and -pb_ratio parameters
control the Quantization Parameter (QP) relationship between these frame
types. QP determines how much lossy compression is applied; a lower QP
means higher quality and larger file size, while a higher QP means lower
quality and smaller file size.
-ip_ratio(I-to-P Ratio): This parameter defines the target quality/quantizer ratio between I-frames and P-frames. It determines how much better the quality of an I-frame should be compared to a P-frame.-pb_ratio(P-to-B Ratio): This parameter defines the target quality/quantizer ratio between P-frames and B-frames. B-frames are highly compressed and rely heavily on neighboring frames, so they typically use a higher QP (lower quality) than P-frames.
Default Values
For standard encoders like libx264, the default values
are generally optimized for a balance of visual quality and
compression:
-ip_ratiodefault:1.40-pb_ratiodefault:1.30
These defaults mean that P-frame QPs are calculated by multiplying the I-frame QP by 1.4, and B-frame QPs are calculated by multiplying the P-frame QP by 1.3.
FFmpeg Command Syntax
To configure these parameters, you pass them as video options in your FFmpeg command line.
ffmpeg -i input.mp4 -c:v libx264 -ip_ratio 1.40 -pb_ratio 1.30 output.mp4When and How to Adjust the Ratios
Adjusting these ratios allows you to fine-tune how bits are allocated across different frame types depending on your specific use case.
1. Tuning for High-Motion Video
In high-motion videos (such as sports or action gameplay), B-frames
can degrade quickly because references change rapidly. *
Action: Decrease -pb_ratio (e.g., to
1.15 or 1.20) to allocate more bits to
B-frames, keeping their quality closer to P-frames. *
Example:
bash ffmpeg -i input.mp4 -c:v libx264 -ip_ratio 1.40 -pb_ratio 1.15 output.mp4
2. Tuning for Maximum Compression (Low Bitrate)
If you need to compress a video as much as possible (such as
talking-head videos or static presentations) and do not mind a slight
drop in overall quality, you can increase the ratios. *
Action: Increase -pb_ratio (e.g., to
1.40 or 1.50) so B-frames discard more
redundant data. * Example:
bash ffmpeg -i input.mp4 -c:v libx264 -ip_ratio 1.45 -pb_ratio 1.40 output.mp4
3. Tuning for Constant Quality (Uncompressed/Lossless Feel)
If you want almost uniform quality across all frame types, you can
set the ratios closer to 1.0. Note that this will
significantly increase the output file size. * Action:
Set both ratios close to 1.0. * Example:
bash ffmpeg -i input.mp4 -c:v libx264 -ip_ratio 1.10 -pb_ratio 1.10 output.mp4