Ch. 11 · Measuring Video Quality in Practice

한국어日本語
8 min

Computing BD-rate from Your Own Data

Build two R-D curves and work out for yourself how many percent the file size differs at the same quality. The hands-on version of the Chapter 2 concept.

In Chapter 2 you learned that BD-rate is the bitrate difference at the same quality, averaged over a section of the curves. Now let's see the steps for computing it from your own measurement data. The tables in this site's measurement articles are exactly the shape of the raw material: an R-D curve with one row per CRF step, each holding a bitrate and a VMAF value.

The steps

  1. 1Encode the two settings you want to compare (A: baseline, B: candidate) from the same clip at several CRFs, and measure the bitrate and quality (VMAF) at each point. You normally use four or more points.
  2. 2Take the log of the bitrate. Bitrate moves in multiples, so the curve is easier to handle on a log scale.
  3. 3Put quality on the horizontal axis and log bitrate on the vertical axis, and connect the points with a smooth curve (the classic method is a cubic polynomial).
  4. 4Pick only the range where the two curves' quality overlaps, and use integration to find the difference in the average height of the two curves within that range.
  5. 5Convert the log difference back with an exponential and express it as a percentage. If it is negative, B reached the same quality with fewer bits.
BD-rate with the classic cubic polynomial method (needs 4 or more points)
import numpy as np

def bd_rate(rate_a, q_a, rate_b, q_b):
    """BD-rate (%) of B relative to A. Negative means B uses fewer bits at the same quality."""
    la, lb = np.log(rate_a), np.log(rate_b)
    pa = np.polyfit(q_a, la, 3)
    pb = np.polyfit(q_b, lb, 3)

    lo = max(min(q_a), min(q_b))   # the range where quality overlaps
    hi = min(max(q_a), max(q_b))

    ia, ib = np.polyint(pa), np.polyint(pb)
    avg_a = (np.polyval(ia, hi) - np.polyval(ia, lo)) / (hi - lo)
    avg_b = (np.polyval(ib, hi) - np.polyval(ib, lo)) / (hi - lo)
    return (np.exp(avg_b - avg_a) - 1) * 100
The idea of "comparing file size at the same quality" is the heart of it

The average VMAF measurement on this site, which used interpolation to find the CRF and file size that hit "average 95 and minimum 90," rests on the same idea. But the size ratio in that article (for example, about 2.29 times for riverbed x264) is a size ratio between two different quality targets, which is a different question from the BD-rate that compares two codecs. It is the same tool (reading file size off the quality axis) applied to a different question.

Safety rules for reading BD-rate

  • Which quality metric? A PSNR-based BD-rate and a VMAF-based BD-rate are different numbers. If it is VMAF, state the model too (lesson 2).
  • Only the overlapping range is valid. If the quality ranges of the two curves barely overlap, you get a distorted number that is close to extrapolation. Saturated points (where VMAF sticks in the high 90s) also distort the curve, so it is safer to drop the saturated region and use only the range you care about, as this site's measurements do.
  • Remember that it is based on average quality. As you saw in lesson 3, the minimum can differ greatly even when the average is the same. A BD-rate computed from average VMAF does not guarantee "instantaneous quality."
  • Don't generalize from one or two pieces of content. BD-rate figures from standardization meetings come from a fixed test set under common test conditions (CTC). A value from a few of your own clips is a statement about those clips.
In the field: record the curve interpolation method too

Besides cubic polynomials, some implementations use piecewise interpolation (such as PCHIP), and the value can differ slightly depending on the method. When you share a number, include the metric (PSNR or VMAF, and the model), the number of points used and their CRF/QP, the interpolation method, and the quality range, so that others can reproduce it.

To sum up the flow of this chapter: ① pick the metric and the model (lessons 1-2), ② look at the tail as well as the average (lesson 3), ③ match the measurement conditions (lesson 4), ④ measure with a command (lesson 5), and ⑤ compare with curves (lesson 6). If you want to practice on real data, you can download the points from the CSV under a measurement article and feed them into the function above.

Closing thoughts

This was an advanced chapter added to a course you may have thought was finished at Chapter 10. The one-line summary is that measuring results without fooling yourself and describing them without exaggeration matters as much as building a codec. When you meet a number, first ask: "Which metric, which model, the average or the tail, and under what conditions?"

R-D curveRate-distortion curve

A curve connecting points that show the relationship between bitrate (file size) and quality. The raw material for BD-rate.

Overlap rangeOverlap range

The quality range that two R-D curves both cover. BD-rate is meaningful only within this range.

CTCCommon test conditions

The content set and settings agreed on at standardization meetings. BD-rate comparisons outside these conditions are hard to generalize.

Check yourself

What if the quality ranges of the two curves barely overlap when you compute BD-rate?