Log in

View Full Version : increasing b-frame is good or not?


huang_ch
13th June 2006, 20:56
I'm trying x264 these days, and I've read some posts here which mentioned that increasing b-frame to above 3 may be useless for the encoder itself may hardly choose to use b-frame above 3. But in a recent try, I've found that by increasing b-frame to 16, the final bitrate is decreased a lot and PSNR also decreases.
All uses crf24, the raw file is a anime
1. b-frame 16: final bitrate: 288Kbps, PSNR: Avg:45.054 Global:44.097
2. b-frame 3: final bitrate: 335Kbps, PSNR Avg:46.512 Global:45.068

Is this the expected behavior? Increasing b-frame will reduce the bitrate but also PSNR? Though I didn't see many major loss with my eye....

AlexB17
13th June 2006, 21:05
Anime is anime - don't think you get same result on real life footage or movie

foxyshadis
14th June 2006, 00:07
That might be due to the difference between P and B frame quantizers; what if you lower the crf to bring the first bitrate in line with the other? Try to control all but one variable to make useful conclusions. What if you measure with SSIM? Most importantly, are they adaptive?

If controlling for bitrate results in higher quality in 3-b still, obviously chuck it. If it shows 16-b is higher, by metrics and visual or just metrics and no visual difference, then you can make a rough recommendation: Use a lower crf when using lots of b-frames with anime.

Kurth
14th June 2006, 02:55
I always use 16 B-Frames with Adaptive B-Frames for my Anime encodes it help a lot to make a 25 minutes episode fit in a 100MB file with a very good quality.
Well I use all very slow options of the encoder hehehe so I dont get this high diference on PSNR like you had on your test xD
On anime there is a lot of scenes that the imagem dont have any high movement for a lot of time and the anime image dont have a lot of details like a real movie and if your read the Stats file after doing the 1st Pass you can see a lot of places with more than 3 consecutive B-Frames and I even saw some scenes that the encoder used like 8-12 consecutive B-Frames.
I really think that you can use Adaptive 16 B-Frames without any problems when you are doing encodes that is going to have a small file size.

To get a diference of 1.0 PSNR that he got I really think that he dont used Adaptive B-Frames.
16 B-Frames without Adaptive you always lose a lot of quality.

GodofaGap
14th June 2006, 06:59
Uhm...

The only sane way of comparing PSNR scores is doing a 2-pass with a fixed bitrate, not crf or qp modes. Just 10 kbps can already make a big difference in PSNR sometimes.

huang_ch
14th June 2006, 07:52
foxyshadis & Kurth, I'm pretty sure that I use b-adaptive feature. Below is the command line I used for the encode:
--crf 24 --ref 5 --mixed-refs --bframes 16 --b-pyramid --b-rdo --bime --weightb --direct auto --filter 4,4 --subme 6 --trellis 2 --analyse all --8x8dct --qpmin 14 --qpmax 28 --ipratio 1.6 --pbratio 1.6 --me umh --progress --no-dct-decimate

I'm keeping trying to adjust --crf, --qpmin/max, --bframes, --ref, --ipratio/pbratio these days.

Audionut
14th June 2006, 08:09
With adaptive b-frames enabled, the number of b-frames becomes the maximum number of b-frames that the encoder can use.

The encoder will then use however many b-frames it thinks are best.

Obviously with the content you are encoding, more b-frames is good.

Without adaptive b-frames, if you specify 2 b-frames, that is how many will be used.

huang_ch
14th June 2006, 08:29
With adaptive b-frames enabled, the number of b-frames becomes the maximum number of b-frames that the encoder can use.

The encoder will then use however many b-frames it thinks are best.

Obviously with the content you are encoding, more b-frames is good.

Without adaptive b-frames, if you specify 2 b-frames, that is how many will be used.
Why you say more b-frames is good for my content? Though the bitrate decreased a lot, but the PSNR also decreased by ~1.0. (Though no obvious visual decrease...)

Kurth
14th June 2006, 08:51
Maybe using 16 B-Frames Adaptive only work better on a 2-Pass Encode because I always use 2-Pass and I dont have any problem.
Did you really need to use a constant quality encode? You will get better quality using a 2-pass Encode.

huang_ch
14th June 2006, 08:55
foxyshadis, I've finished SSIM analyze on two videos, below is the result:
1. b16: 89.06
2. b3: 91.00

Still lossing that amount of bitrate cause the quality loss. I'll try to have a similar bitrate to compare.

huang_ch
14th June 2006, 09:04
Maybe using 16 B-Frames Adaptive only work better on a 2-Pass Encode because I always use 2-Pass and I dont have any problem.
Did you really need to use a constant quality encode? You will get better quality using a 2-pass Encode.

I've tried 2 pass with b-3, but got a not so competetive result in PSNR than any other methods. Below is the result for 2 pass with b-3
bitrate 350Kbps, PSNR Avg:46.274 Global:45.262
while another try with crf24, b3, qpmin/max-13/28 produces: 341Kbps, PSNR Avg:46.938 Global:45.318

So I think it's better to stick with crf mode.

Audionut
14th June 2006, 09:52
My bad, I thought you had increased psnr with 16 b-frames.

Ignore,
Obviously with the content you are encoding, more b-frames is good.

If a bitrate of 350kbps is what your shooting for, then follow foxyshadis advice.
what if you lower the crf to bring the first bitrate in line with the other?

Encode with 16 b-frames but with crf 23 or 22, so that the resulting bitrate is closer to 330-350kbps.

huang_ch
14th June 2006, 10:58
My bad, I thought you had increased psnr with 16 b-frames.

Ignore,


If a bitrate of 350kbps is what your shooting for, then follow foxyshadis advice.


Encode with 16 b-frames but with crf 23 or 22, so that the resulting bitrate is closer to 330-350kbps.
Thanks for clarify, indeed, I'm not shooting for any bitrate, I'm new to x264, so just interesting in trying to see how low the bitrate could be to encode one of my video. So I want to try any options to make it as low as possible.

Also, another question is, since I've got 89-91 for SSIM, I think this score may be pretty high, right? Are there any former experience from any one can share with me that what SSIM & PSNR value you've got for your videos which you think its quality is pretty good. Is there any relationship between SSIM/PSNR with visual quality? I mean for example, a SSIM above a special value could be regarded as a rather good quality.

Audionut
14th June 2006, 13:23
Use your eyes!!

huang_ch
14th June 2006, 13:37
Use your eyes!!
That's what I'm doing these days, but I just want to ask for some experiences from your guys to fasten the progress. :)

imcold
14th June 2006, 17:08
With adaptive b-frames enabled, the number of b-frames becomes the maximum number of b-frames that the encoder can use.

The encoder will then use however many b-frames it thinks are best.


nope.. encoder uses max. so many b-frames as defined or fewer. It decides where many b-frames are useful and where they aren't, so with adaptive the frame sequence could look like this (3 b-frames) : I BB P BBB P P B P... instead of I BBB P BBB P BBB P....

foxyshadis
14th June 2006, 19:54
Nono, you misread him; he meant that switching on adaptive changes the meaning of the b-frames switcher box to "maximum" instead of "constant".

imcold
14th June 2006, 20:24
oops.. sorry.

huang_ch
15th June 2006, 02:13
Yes, so I fully understand that it is Adaptive, and x264 does seems to use more b frames after the max is set to 16, but the overall bitrate & PSNR is also decrease a bit.
So the main target that b-frame is introduced to video codecs is to increase the bitrate efficiency or increase the quality? I'm a bit confused...

Audionut
15th June 2006, 06:08
Substantially reduce bitrate without a great loss in quality.

Audionut
15th June 2006, 06:13
and x264 does seems to use more b frames after the max is set to 16, but the overall bitrate & PSNR is also decrease a bit.

Hence why people don't allow the encoder to use a maximum of 16 b-frames and set the maximum to say 3 b-frames.

However!!! Your first post states that you did not see any major loss of video quality to your eyes with a max of 16.
So don't bother with metric calculations. Just use max 16.

Sagittaire
15th June 2006, 07:47
--crf 24 --ref 5 --mixed-refs --bframes 16 --b-pyramid --b-rdo --bime --weightb --direct auto --filter 4,4 --subme 6 --trellis 2 --analyse all --8x8dct --qpmin 14 --qpmax 28 --ipratio 1.6 --pbratio 1.6 --me umh --progress --no-dct-decimate

1) Well you must use constant size if you want make real comparison. More and more bframe with ratio for bframe imply less size and less quality too simply because average quantizer is more and more high.

2) If you want see bframe adaptive efficacity use crf with ratio = 1.0 for bframe. Here IMO if the adaptive algo is good then size will be less important with constant quality.

3) ipratio = 1.6 is totaly useless. Quality for IFrame will be too high and will produce certainely quality dropp.

huang_ch
15th June 2006, 14:01
I've tried to increase the value of -crf(25,26) to get the bitrate of bframe-3 closer to 288Kbps (b-frame16) and the PSNR is also about 0.3 higher than b-frame16 with crf24. Does this mean I should prefer less b-frame with higher crf than higher b-frame with lower crf to encode this content? Even try b-frame1?

huang_ch
15th June 2006, 14:04
3) ipratio = 1.6 is totaly useless. Quality for IFrame will be too high and will produce certainely quality dropp.
I'm not quit familiar with --ipratio & --pbratio, but after I increase them all to 1.6 from the default 1.4/1.3, the PSNR really increased a bit. But I didn't try to individually increase them, will try later.

Sagittaire
15th June 2006, 16:09
Well if you don't know then simply don't touch default setting ... :D

Use 16 adaptative bframe is simply useless because in most case x264 never use it (no more than 3 bframe for perhaps 99.9% of the cases). IMO best setting are 2 bframes or 3 pyramidal bframes. Use "over setting" for max bframe is simply useless and potentially worst if you use no adaptative bframe.

MeteorRain
15th June 2006, 18:16
I'm not quit familiar with --ipratio & --pbratio, but after I increase them all to 1.6 from the default 1.4/1.3, the PSNR really increased a bit. But I didn't try to individually increase them, will try later.
eg if you use ip/pb ratio 1.6, and if your p-frame is encoded in q24, then i-frame would be q15 and b-frame would be 38~39

mean, i-frame encoded in really good quality, and b-frame encoded in really bad quality.

when you use more b-frames, since the quantizer rises, the filesize reduces, the quality decreases.

if you want a real comparation about the problem, you could consider setting ip/pb ratio to 1.0, or just use -qp instead of -crf. in that case, b-frame is encoded at the same quantizer of p-frame. using more b-frames won't decrease quality lot.

akupenguin
15th June 2006, 21:51
eg if you use ip/pb ratio 1.6, and if your p-frame is encoded in q24, then i-frame would be q15 and b-frame would be 38~39
No. ip- & pb-ratio are measured in bitrate (as a bonus on top of the different rates inherently caused by different frame types), not in QP.
QP is an exponential scale, so it does not make sense to ever multiply a QP by anything.

huang_ch
16th June 2006, 03:31
No. ip- & pb-ratio are measured in bitrate (as a bonus on top of the different rates inherently caused by different frame types), not in QP.
QP is an exponential scale, so it does not make sense to ever multiply a QP by anything.
Is the ratio used as a constant ratio or an adaptive(maximum) ratio?

akupenguin
16th June 2006, 05:04
pb-ratio is constant.
ip-ratio is a maximum, and in 2pass it will decrease for very short GOPs.

Audionut
16th June 2006, 07:14
That explains why, with a low ip-ratio it will often result in a lower average P quant than I quant.

Thanks.

akupenguin
16th June 2006, 10:49
What explains what?

The reason you can have higher average I quant than average P-quant is that high motion scenes get higher quant than low motion, and high motion scenes have more scenecuts.
That would be true regardless of how ip-ratio works, though for large ip-ratio you'd need a very uneven distribution for the averages to still end up like that.
(Same for P vs B)

Audionut
16th June 2006, 13:46
With all the encodes I have done thus far, with the default ip-ratio of 1.4, the P frame quantizers are always are higher value than I frame quantizers.
Say I-frames = quant 17 and P-frames = quant 18

But if I reduce the ip-ratio to 1.05 or even 1.10, then often (not always), I generally end up with P frame quantizers that have a lower value than I frame quantizers.
Say I-frames = quant 17 and P-frames = quant 16.8

I never expanded on why this would be the case.
When you said that ip-ratio is a maximum value and not an absolute value I assumed that was the reason why lower ip-ratio's would result in the findings as stated above.


Thanks for the clarification. Again.

unmei
16th June 2006, 14:18
Use 16 adaptative bframe is simply useless because in most case x264 never use it (no more than 3 bframe for perhaps 99.9% of the cases).

I definitly wouldn't say that. Or a lot of my anime and esp. cartoon encodings fall into the remaining 0.1% :)
I never checked the stats file, but from x264 stats at the end of the encode it's not so uncommon for me to have close to 3 B-frames per one P-Frame and in a recent case i had over 3.5 B-frames per P-frame (as per the total number of frames encoded in each mode, thus the overall average).

huang_ch
16th June 2006, 16:32
But if I reduce the ip-ratio to 1.05 or even 1.10, then often (not always), I generally end up with P frame quantizers that have a lower value than I frame quantizers.
Say I-frames = quant 17 and P-frames = quant 16.8

Does that mean, if I reduced ip ratio to rather low, and got quant of p higher than I, the overall quality/quant will be improved? Is it the same to b-frames?