Encoding Brief: The Benefit of B-frames

Executive Summary: B-frames increase compression efficiency, particularly at lower bitrates. However, not all video encoders deliver the requested number of B-frames when encoding using default parameters. Telestream Switch is a software program that identifies B-frames in encoded streams, and computes the overall B-frame percentage. Compressionists seeking the most efficient streams should acquire Switch and test their streams. If B-frames are not optimized, they should disable adaptive B-frame placement in their encoding tool, but also check to make sure this improves, and doesn't degrade quality. 

Overview and Discussion: Sometimes a new tool reveals information in a new way that causes you to rethink the importance of different encoding parameters. For example, check out this screen from Telestream Switch Pro (the $295 version, not the free version). By way of background, I was producing some test files for a client using FFmpeg, and didn't specify any B-frame related parameters. When I inspected the file in Switch, I saw this screen, which shows P-frames in purple, and B-frames in blue. What caught my eye was the B-frame percentage on the upper right, of 34%, which means that only 34% of frames are B-frames. For the record, this sequence of frames, which caught the video during a fade transition, are almost all P frames, reflecting x264's default behavior of enabling adaptive B-frame placement. 

TBorNotTB_1.PNG

As we all learned in Compression 101, B-frames are bi-directional interpolated, which means they look backwards and forewords for redundancies. This makes them more efficient than P-frames, which only look backwards, and I-frames, which don't look in either direction and are totally self-referential. You can see this in the figure, since the B-frames are smaller than the P-frames. 

This figure got me thinking, "How much more effectively would the video compress if I forced more B-frames?" I am an FFmpeg newbie, but the scheme I came up with was to specify the number of B-frames in the stream, and choose 2 for the -b_strategy. I got this strategy here, which describes 2 as "A much slower but more accurate B-frame decision mode that correctly detects fades and generally gives considerably better quality. Its speed gets considerably slower at high bframes values, so its recommended to keep bframes relatively low (perhaps around 3) when using this option. It also may slow down the first pass of x264 when in threaded mode." 

In the command line string, these two commands look like this;

-bf 3 -b_strategy 2

I re-encoded the file, and the frame sequence now looks like this for the same region in the file. As you can see, the B-frame interval of 3 is rigorously enforced, and the B-frame percentage is now up to 71%, nearly double that of the previous file. 

TBorNotTB_2.PNG

Of course, the big question is, how does this impact quality? I originally tested at around 1080p@12 Mbps (all tests at 23.976 fps), and the extra B-frames actually decreased quality according to SQM, PSNR, and VQM metrics, a real man-bites-dog story. Then I tested at both 6 Mbps and 2 Mpbs at the same resolution and the situation reversed. All scores are shown in the table below.

TBorNotTB_3a.PNG

To explain, the SQM score is from SSIMWave's Quality of Experience Monitor, the VQM the Video Quality Metric as measured by the Moscow University Video Quality Measurement Tool, and PSNR the Peak Signal-to-Noise Ratio as measured by the Moscow University tool. The green background shows the best score for each file and each test. As shown in the table, lower is a better score for the VMQ, higher is better for both other metrics. The last column on the right for each metric shows the percentage difference. 

To explain ever further, SQM scores correlate with projected subjective evaluations, with any score above 80 projecting an excellent rating. Pretty impressive results at 2Mbps (1080p@23.976 fps), wouldn't you say? I tested with VQM because it's generally a more sensitive metric than either of the others, though the scores don't correlate with any projected subjective rating. 

In their recent Per-Title-Encoding blog post, Netflix commented that PSNR scores of around 35 dB or so typically reflect visible artifacts in the video, while scores over 45 dB show imperceptible quality improvements, essentially wasted bandwidth. All scores are between the two extremes, with even the 2 Mbps streams comfortably away from the 35 dB quality floor. 

You would think that doubling the amount of B-frames in a file would do more than bump quality by about 1% or so. Definitely worth chasing, but nothing to ring a client and shout, "hey, look what I did for you!"

That said, compression excellence is about many little gains, so I'll keep tinkering and see what the net improvement adds up to be. In the meantime, if you're really going low data-rate-wise, it's worth getting a tool like Switch to check the B-frame %. I first noticed the difference when comparing files encoded by my consulting client in Premiere Pro (high B-frame %) and their cloud provider (low B-frame %). Without a tool like Switch, I never would have noticed. 

At the other end of the quality spectrum, if you're producing mezzanine files for uploading to a cloud encoder (or similar facility), you might perform similar tests, as more B-frames actually degraded quality at the highest tested bandwidth. 

Recommendations:

1. Purchase Switch Pro, or another tool that provides similar visibility into the frame types deployed in your encoded files.

2. Test your encoded files. If B-frames are not deployed at or close to the desired interval (usually 3-5), change the default settings of your encoder to disable adaptive B-frame placement. Note that not all encoding tools will offer this option. 

3. Check before and after quality with a tool like the Moscow University or SSIMWave Tools to ensure that forcing the keyframes improved overall quality. 

Additional Resources: 

Presentation: Fine-Tuning Your Adaptive Groups with Objective Quality Metrics, Streaming Media West, 2015 (downloadable handout and video).

Review: Moscow State University Video Quality Measurement Tool, Streaming Media Europe, October 2014.

Review: SSIMWave Quality of Experience Monitor, Streaming Media Magazine, October, 2015.

Udemy Course: Encoding for Multiple Screen Delivery, www.udemy.com, 18 lessons, 2.5 hours of instruction. 

About the Streaming Learning Center:    

The Streaming Learning Center is a premiere resource for companies seeking advice or training on cloud or on-premise encoder selection, preset creation, video quality optimization, adaptive bitrate distribution, and associated topics. Please contact Jan Ozer at jan@streaminglearningcenter.com for more information about these services.

The Streaming Learning Center is a premiere resource for companies seeking advice or training on cloud or on-premise encoder selection, preset creation, video quality optimization, adaptive bitrate distribution, and associated topics. Please contact Jan Ozer at jan@streaminglearningcenter.com for more information about these services.


Comments (0)

New comments are currently disabled.