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.
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) * 100The 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.
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.
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?"
A curve connecting points that show the relationship between bitrate (file size) and quality. The raw material for BD-rate.
The quality range that two R-D curves both cover. BD-rate is meaningful only within this range.
The content set and settings agreed on at standardization meetings. BD-rate comparisons outside these conditions are hard to generalize.
What if the quality ranges of the two curves barely overlap when you compute BD-rate?