Log in

View Full Version : B-frames quality questions (x264)


andiandi
17th November 2019, 18:28
I was wondering if we could improve quality of b-frames without causing any issues, nor increasing filesize so much if possible/realistic. I'm aware that we don't watch a video frame by frame, but it still can be important with some videos in which pausing frequently on several moments is useful (e.g. family tapes...), or, if we want to take screenshots...

The thing is that I don't want to use custom settings without any advices, so I have some questions (note that I'm usually using 5-6 b-frames along with b-adapt 2 and b-pyramid) :

1) If I change ipratio value, would it change the quality of EVERY b-frame or just those which are using pframes as reference ?
Or do I HAVE to change both ipratio and pbratio values so that all b-frames would have a quality improvement.

2) I read here and there that pbratio doesn't work if mbtree is enabled, so if we use Grain Tune for instance, which enable both ipratio and pbratio, will mbtree be ignored if it's enabled ?
If yes, do you have any advise on how to "compensate" compression loss (e.g. in high motions) due to no-mbtree ?

3) I just want to have a close quality between b-frames and default "medium preset" pframes (or at least, not too much lower). So, can I achieve this by changing a bit ipratio and pbratio, or do I have to choose more "extreme" values just like Grain Tune do ? (Grain Tune is just an example, my goal isn't grain retention).
Note that I'm not bothered by low quality bframes in high motion moments, but rather in low motion moments.

4) If we change ipratio and pbratio, is it a good idea to decrease psy-rdo (the first value) to compensate ipratio/pbratio bitrate consumption.
Or maybe you have other advises to improve compression ?

Thank you

Rumbah
17th November 2019, 22:12
If you want at least p-frame quality and don't care that much about space, why don't you just deactivate b-frames altogether?

andiandi
17th November 2019, 22:33
If you want at least p-frame quality and don't care that much about space, why don't you just deactivate b-frames altogether?

Thanks for your reply.
Because by using b-frames we can make them a bit lower quality than p-frames (but not as low quality as the default preset).

Also, b-frames are more efficient for compression than p-frames (efficiency of bi-prediction).

l00t
18th November 2019, 09:37
You may add a --pbratio switch, which acts similarly to ipratio (except it adjusts the P:B ratio). Please be aware, that x264 will ignore this switch when using MB-Tree, so adding a --no-mbtree is necessary in this case.

andiandi
18th November 2019, 23:14
You may add a --pbratio switch, which acts similarly to ipratio (except it adjusts the P:B ratio). Please be aware, that x264 will ignore this switch when using MB-Tree, so adding a --no-mbtree is necessary in this case.

Hi, Ok.
But if I only change pb-ratio wouldn't it decrease p-frames quality ? (By taking extra bits from p-frames and allocate them to b-frames).
If yes, should I change ipratio too, in order to maintain p-frames quality ?

andiandi
18th November 2019, 23:21
and don't care that much about space

I forgot to reply to this.
Actually I care about space/filesize, but I guess that there will probably be no "miracle" if we use higher quality b-frames rather than default lower quality b-frames.

That's why I'm asking for other advices/tips to improve compression in that case.

Rumbah
19th November 2019, 13:04
Well, you just have to test it for yourself to see what you like.

I did a quick test for you to perhaps give you a starting point:

Source is uncompressed Tears of Steel 1080p.
Base command line is x264 --preset veryslow --tune film --level 4.1

"Without b-frames" is with added --bframes 0.
"Pbratio 1" is with --pbratio 1.0 --no-mbtree.
"+10%" is with 10% bitrate added.

https://i.ibb.co/YNVwqs0/bframes.png (https://ibb.co/hgTwtzY)

As you see the differences aren't that big, and without b-frames might even be better than with big b-frames and without mbtree.

benwaggoner
19th November 2019, 17:47
"Without b-frames" is with added --bframes 0.
"Pbratio 1" is with --pbratio 1.0 --no-mbtree.
"+10%" is with 10% bitrate added.

https://i.ibb.co/YNVwqs0/bframes.png (https://ibb.co/hgTwtzY)

As you see the differences aren't that big, and without b-frames might even be better than with big b-frames and without mbtree.
I'm not sure how relevant averages of per frame scores are in this case, since the issue with B-frames is quality variability. Looking at the variance of VMAF scores is probably the easiest relevant thing to try.

andiandi
19th November 2019, 19:25
Well, you just have to test it for yourself to see what you like.

I did a quick test for you to perhaps give you a starting point:

Source is uncompressed Tears of Steel 1080p.
Base command line is x264 --preset veryslow --tune film --level 4.1

"Without b-frames" is with added --bframes 0.
"Pbratio 1" is with --pbratio 1.0 --no-mbtree.
"+10%" is with 10% bitrate added.

https://i.ibb.co/YNVwqs0/bframes.png (https://ibb.co/hgTwtzY)

As you see the differences aren't that big, and without b-frames might even be better than with big b-frames and without mbtree.

Thank you.
Interesting, particularly for mbtree.
Maybe pb-ratio 1.0 is too much. I may be wrong but I guess that since b-frames are more efficient than p-frames, they can have a close quality to p-frames even with lower quantizers, which may improve compression since there no mbtree when pb-ratio is used.

andiandi
19th November 2019, 19:30
Looking at the variance of VMAF scores is probably the easiest relevant thing to try.

Can final ratefactor be a good way of comparison in that kind of case ?
Sometimes, I also check that to compare compression

benwaggoner
20th November 2019, 03:09
Can final ratefactor be a good way of comparison in that kind of case ?
Sometimes, I also check that to compare compression
Maybe? I've not tested RF variance between I/P/B/b.

andiandi
25th November 2019, 17:54
Hi.

I made some encoding tests with a full movie in 720p 1800Kbps which have few grain and many high motion scenes, to look at final ratefactor and frames quantizer :



- B-frames + mbtree (rc-lookahead:50) :

final ratefactor: 21.75
frame I:1543 Avg QP:19.34 size: 72976
frame P:35636 Avg QP:22.32 size: 19431
frame B:111983 Avg QP:24.61 size: 5236


- No B-frames + mbtree (rc-lookahead:50) :

final ratefactor: 22.82
frame I:3370 Avg QP:22.10 size: 34683
frame P:145792 Avg QP:24.11 size: 8770

- No-mbtree + pb-ratio 1.0 :

final ratefactor: 23.48
frame I:1521 Avg QP:21.07 size: 54209
frame P:36751 Avg QP:23.47 size: 15013
frame B:110890 Avg QP:23.37 size: 6827

- No-mbtree + pb-ratio 1.1 :

final ratefactor: 22.90
frame I:1521 Avg QP:21.09 size: 54120
frame P:36751 Avg QP:22.94 size: 16398
frame B:110890 Avg QP:23.54 size: 6377



As we can see, based on the final ractefactor (if it's relevant enough), it confirms that No B-frames + mbtree gives a better compression than pb-ratio without mbtree.

But frames quantizer shows that for No b-frames + mbtree, p-frames have a worse quantizer than both p-frames and b-frames with pb-ratio + no-mbtree.

I don't know how to feel about it since both (no b-frame + mbtree and pbratio + no-mbtree) seems to have their advantages.