PDA

View Full Version : Why do B-frames decrease quality?


Dark Shikari
19th August 2007, 05:40
I'm using FFDShow's built-in MPEG-2 encoder with Virtualdub to test out MPEG-2 in comparison to some more modern codecs. On my sample video at 2 megabits per second ABR, Xvid gets just over 0.97 SSIM and MPEG-2 without B-frames gets about 0.9658 with some heavily optimized motion search settings. However, if I add B-frames (dynamic + refine checked), the quality drastically drops at the same bitrate, and SSIM gets as low as 0.94.

Why? Is it because I'm using the AVI container? Or is something else going on?

Sagittaire
19th August 2007, 10:10
ffdshow is not a really good tool for make test with MPEG2. Anyway default setting are not the best for bframe:
- High ratio/offset at 1.25/1.25. The bframe are really surquantized and produce high local quality difference.
- The best mode for bframe placement is strategy at level 2. Libavcodec use RDO for bframe placement in this case.

Little test at constant quantizer q2 (I, P & B) with libavcodec, 720*576, 720*320 at 4/3 ratio for real image, HPII trailer, 3213 frames

No adaptative bframe at 2 with sad/rdo/trelli search: 3007 Kbps at 49.58 dB
Simple adaptative bframe at 2 with sad/rdo/trelli search: 2892 Kbps at 49.54 dB
rdo adaptative bframe at 2 with sad/rdo/trelli search: 2837 Kbps at 49.55 dB
rdo adaptative bframe at 2 with sad/chroma/rdo/trelli search: 2832 Kbps at 49.57 dB
rdo adaptative bframe at 2 with sadt/rdo/trelli search: 2799 Kbps at 49.60 dB
rdo adaptative bframe at 2 with sadt/chroma/rdo/trelli search: 2795 Kbps at 49.62 dB
rdo adaptative bframe at 1 with sadt/chroma/rdo/trelli search: 2803 Kbps at 49.60 dB
rdo adaptative bframe at 0 with sadt/chroma/rdo/trelli search: 2847 Kbps at 49.51 dB

And here it's just constant quant comparison. Bframe are efficient optimal (visual quality too) with small ratio/offset like 1.25/0.00 or 1.00/1.00.

Blue_MiSfit
19th August 2007, 12:21
Do keep in mind that metrics aren't really an accurate representation of perceived image quality.

Don't go by the numbers, go by your eyes :)

Just my 2 cents!

~MiSfit

akupenguin
19th August 2007, 13:16
But B-frames should improve metrics. If you say "why do B-frames look worse?", then there might be a problem in the codec, or there might be a problem in your eyes ;). But if you say "why do B-frames reduce metrics?" then that's something reproducible and definitely wrong.

Dark Shikari
19th August 2007, 13:34
But B-frames should improve metrics. If you say "why do B-frames look worse?", then there might be a problem in the codec, or there might be a problem in your eyes ;). But if you say "why do B-frames reduce metrics?" then that's something reproducible and definitely wrong.
And dropping the SSIM from 0.965 to 0.94 is going to be very, very noticable (and it is).

I'm also very surprised that I could get the SSIM on a 1280x720 video to be nearly as good in MPEG-2 as with Xvid. Or, better said, I'm very surprised that Xvid was so low.

Sagittaire
19th August 2007, 14:54
And dropping the SSIM from 0.965 to 0.94 is going to be very, very noticable (and it is).

I'm also very surprised that I could get the SSIM on a 1280x720 video to be nearly as good in MPEG-2 as with Xvid. Or, better said, I'm very surprised that Xvid was so low.

The SSIM drop because:
- bframe placement are not optimal
- Too high ratio (with bad placement) with bframe produce very bad quality for bframe and bad quality for SSIM.

Dark Shikari
19th August 2007, 17:24
The SSIM drop because:
- bframe placement are not optimal
- Too high ratio (with bad placement) with bframe produce very bad quality for bframe and bad quality for SSIM.
How do I improve the placement? Is there a better encoder than FFDshow VfW that supports RDO and such features?

FlixnPix
23rd August 2007, 00:32
I've got to agree with DarkShikari on this. I'd never noticed it before. A few days ago I completed about 27 hours of video capture and have converted it all to MPEG2 thru QuEnc via AviSynth. I read DarkShikari's post for the first time today and tried a few tests myself. I was astounded. There is a picket fence which is very prominent in two of the films I've recorded. With B frames left at their default value, the gaps between the fence-posts kinda blur into one another and the detail beyond appears to be slightly out of focus. There is also a faint 'ghost' outline which preceeds each fence-post as it moves. (An effect which has annoyed me for a long time in fact!). In the 30 second test I did with B frames switched off completely the picket fence (which is moving relative to me) appears brilliantly in focus, the detail beyond is as sharp as it is in the original AVI captures and the 'ghost' outline has disappeared completely.

I'm so impressed that I've not long started re-coding all 27 hours of video with no B frames! The increase in fine detail is quite remarkable.

Thanks Dark Shikari! Nice one!

Dark Shikari
23rd August 2007, 03:32
I've got to agree with DarkShikari on this. I'd never noticed it before. A few days ago I completed about 27 hours of video capture and have converted it all to MPEG2 thru QuEnc via AviSynth. I read DarkShikari's post for the first time today and tried a few tests myself. I was astounded. There is a picket fence which is very prominent in two of the films I've recorded. With B frames left at their default value, the gaps between the fence-posts kinda blur into one another and the detail beyond appears to be slightly out of focus. There is also a faint 'ghost' outline which preceeds each fence-post as it moves. (An effect which has annoyed me for a long time in fact!). In the 30 second test I did with B frames switched off completely the picket fence (which is moving relative to me) appears brilliantly in focus, the detail beyond is as sharp as it is in the original AVI captures and the 'ghost' outline has disappeared completely.

I'm so impressed that I've not long started re-coding all 27 hours of video with no B frames! The increase in fine detail is quite remarkable.

Thanks Dark Shikari! Nice one!
The only thing that really makes sense here is:

a) B-frames not being optimally placed
or
b) MPEG-2 doesn't use B-frames well to begin with

Is QuEnc a totally separate encoder or does it just implement ffmpeg?

Sagittaire
23rd August 2007, 10:02
How do I improve the placement? Is there a better encoder than FFDshow VfW that supports RDO and such features?

Mencoder produce optimal encoding with libavcodec.

Fishman0919
23rd August 2007, 12:10
Mencoder produces great metrics scores but in some of the head to head blind tests I have done. Mencoder gets beaten 86% of the time by HC and CCE Basic.

In both cases, 12 out of 14 people picked HC and CCE Basic over Mencoder.


Mencoder does produce some great quality video... but having the best metrics scores doesn't mean the video is going to be the best to watch.

I couldn't remember... so I when back and checked. It's was a 50/50 split with QuEnc and Mencoder

Sagittaire
24th August 2007, 00:20
For high/medium quantizer the difference is ... enormous. If you want a little demo with Elephant Dream at 6 Mbps for 1080p or 480p, I can make that. In this case Libavcodec is the best for metric and for eyes and by far ...

zambelli
31st August 2007, 09:40
Do higher QPs get used on B-frames in Mencoder, HC and QuEnc?
What I've seen in VC-1, for example, is that the quality improvement largely stems from the fact that B frames get encoded at slightly higher QPs than I's and P's, thus leaving more bits available for I's and P's. Because B's don't get used as reference frames in VC-1, this means higher quality in all reference frames at the expense of slightly softer image quality in the disposable B frames. That tends to bring down the metrics, but to the casual user it's virtually unnoticeable as long as the B frame QP delta is not bigger than 2.0.

akupenguin
31st August 2007, 11:57
lavc uses higher quants for B-frames, unless you encode in constant quant mode.

CruNcher
31st August 2007, 13:34
B-frames visually seen are a two sided sword they surely improve compression but to heavily used (and wrong) they introduce alot of visual problems imho , the more you use advanced compression tools the more you alter the Look & Feel of the input so you have to find the right balance of both without destroying it and not try to (over) optimize (for different source scenarios) for the best compression ratio you can get (nice side effect you automaticly lower decoding complexity), just my 2 cents here and HVS trickery can help alot in this case (low bitrate) and with it you can avoid stuff like the very well known B-frame flicker effect the blurr out every x frame (for non adaptive placeing) is another thing and surely not everyone recognizes it (almost invisible when adaptive placement is used and with the addition of --direct auto in x264).