View Full Version : ipratio & pbratio When To Change?
HD MOVIE SOURCE
8th August 2022, 23:22
Hey,
Just wondering how and when to use ipratio & pbratio?
I read...
ipratio
Default: 1.40
Modifies the target average increase in quantizer for I-frames as compared to P-frames. Higher values increase the quality of I-frames generated.
pbratio
Default: 1.30
Modifies the target average decrease in quantizer for B-frames as compared to P-frames. Higher values decrease the quality of B-frames generated. Not used with mbtree (enabled by default), which calculates the optimum value automatically.
-----------------
So ipratio, if I increased that, the I frames would gain quality, but the P frames would suffer? Wouldn't I want to get the I frame and the P and B frames almost equal in quality?
If I set ipratio 1.0 & pbratio 1.0, does that make I P and B frames equal in quality?
Thanks.
benwaggoner
9th August 2022, 17:59
Generally the cleaner the content, like cel animation, the higher values can be used. And the noisier the source, like heavy film grain, the lower values need to be used.
It really gets down to how accurate the reference for predicted blocks are versus how much residual needs to be coded. For cel animation, prediction can be extremely accurate, with many no-residual predictions if from a clean digital source. Conversely, grainy content requires a lot of residual to capture the high spatial frequency of the noise with entirely random placement from frame to frame. If pbratio is too high, the QP of B/b frames will get pushed a lot higher (lower quality) than the frames they reference, so the fidelity of the grain can visually change a lot between frame types, leading to unpleasant strobing.
A decade from now, these might no longer be concerns. AV1 has a grain synthesis tool where grain can be removed from the source before encoding, parameterized in metadata, and reconstructed on playback. While AV1 itself isn't seeing that much market traction outside of user-generated content, the decoder vendors are implementing the synthesis as a codec agnostic postprocessing module, so other codecs like VVC would be able to use grain synthesis via the same SEI message metadata as AV1 uses.
HD MOVIE SOURCE
14th August 2022, 04:18
Generally the cleaner the content, like cel animation, the higher values can be used. And the noisier the source, like heavy film grain, the lower values need to be used.
It really gets down to how accurate the reference for predicted blocks are versus how much residual needs to be coded. For cel animation, prediction can be extremely accurate, with many no-residual predictions if from a clean digital source. Conversely, grainy content requires a lot of residual to capture the high spatial frequency of the noise with entirely random placement from frame to frame. If pbratio is too high, the QP of B/b frames will get pushed a lot higher (lower quality) than the frames they reference, so the fidelity of the grain can visually change a lot between frame types, leading to unpleasant strobing.
A decade from now, these might no longer be concerns. AV1 has a grain synthesis tool where grain can be removed from the source before encoding, parameterized in metadata, and reconstructed on playback. While AV1 itself isn't seeing that much market traction outside of user-generated content, the decoder vendors are implementing the synthesis as a codec agnostic postprocessing module, so other codecs like VVC would be able to use grain synthesis via the same SEI message metadata as AV1 uses.
Okay, thank you, Ben. Is it always best to run a test on the content that you're encoding to get an idea of the Q distribution of I, P, and B frames?
Like, if I had a piece of content that had an I frame Q of 20, but the P and B frames had 40, would you adjust the ratios to bring the P and B frames more inline?
Is the general goal, to have them roughly equal to each other? Especially in film grain content, where you want a more even distribution of grain quality?
I've been testing the ratios on test patterns, and to keep things even in quality on the Q for each frame, test patterns seem to like ipratio=1.00 & pbratio=1.00. Generally speaking, I'm happy to keep them at these values for most content if the distribution of quality per frame is more equal this way.
benwaggoner
15th August 2022, 21:32
Okay, thank you, Ben. Is it always best to run a test on the content that you're encoding to get an idea of the Q distribution of I, P, and B frames?
Like, if I had a piece of content that had an I frame Q of 20, but the P and B frames had 40, would you adjust the ratios to bring the P and B frames more inline?
I've never seen a 20 QP difference, so I would definitely want to visually inspect those! But no, animation content can look just dandy when B-frames have a higher QP. It's much more content dependent then something one could just optimized based on just one parameter in the .csv log file.
Is the general goal, to have them roughly equal to each other? Especially in film grain content, where you want a more even distribution of grain quality?
Yeah, for grainy content, the gap needs to be smaller, particularly pbratio. ipratio doesn't need to go as low, particularly if using a variable GOP duration instead of a fixed cadence. But actually equal would lose a fair amount of efficiency; that's why --pbratio 1.1 instead of 1.0, which would be truly flat.
I've been testing the ratios on test patterns, and to keep things even in quality on the Q for each frame, test patterns seem to like ipratio=1.00 & pbratio=1.00. Generally speaking, I'm happy to keep them at these values for most content if the distribution of quality per frame is more equal this way.[/QUOTE]
HD MOVIE SOURCE
25th August 2022, 18:15
I've never seen a 20 QP difference, so I would definitely want to visually inspect those! But no, animation content can look just dandy when B-frames have a higher QP. It's much more content dependent then something one could just optimized based on just one parameter in the .csv log file.
Yeah, for grainy content, the gap needs to be smaller, particularly pbratio. ipratio doesn't need to go as low, particularly if using a variable GOP duration instead of a fixed cadence. But actually equal would lose a fair amount of efficiency; that's why --pbratio 1.1 instead of 1.0, which would be truly flat.
I've been testing the ratios on test patterns, and to keep things even in quality on the Q for each frame, test patterns seem to like ipratio=1.00 & pbratio=1.00. Generally speaking, I'm happy to keep them at these values for most content if the distribution of quality per frame is more equal this way.
Okay thank you, I'm trying to encode to 4K UHD-BD right now. I'm doing it to get an understanding of the UHD-BD restrictions, and what can be done on 4K Ultra HD Blu-ray, so I used a closed GOP. With min-keyint=1:keyint=24 and 3 bframes.
When using the same IP ratios of 1 the QP comes in almost equal on all frames, pretty cool. I like that from a consistency point of view. I appreciate the feedback.
rwill
25th August 2022, 19:39
I have a question. Is x265 using B slices for its 'P' picture ?
benwaggoner
30th August 2022, 18:30
I have a question. Is x265 using B slices for its 'P' picture ?
As in generalized B-frames? No, it does not. Generalized B-frames were a popular research topic for H.264, but I've not heard much about it for HEVC. Even though the streams are in spec, not all decoders handle them well and they can make random access slower.
Balling
15th September 2022, 07:47
As in generalized B-frames? No, it does not. Generalized B-frames were a popular research topic for H.264, but I've not heard much about it for HEVC. Even though the streams are in spec, not all decoders handle them well and they can make random access slower.
Not anymore, we fixed open gop hevc, as produced by iphones. https://github.com/FFmpeg/FFmpeg/commit/ab77b878f1205225c6de1370fb0e998dbcc8bc69
There is no I, P, B in hevc, not really. CRA are keyframes...
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.