Ch. 2 · Principles of Compression

한국어日本語
8 min

Rate-Distortion Optimization (RDO) and the Lagrangian Cost J = D + λR

How video encoders trade bits for quality: rate-distortion theory, the Lagrangian cost J = D + λR, and why RDO lives in the encoder, not the standard.

At every block, an encoder faces dozens of choices. Which block size? Which prediction mode? Which quantization step? The one piece of math running through all these choices is Rate-Distortion Theory.

The rate-distortion trade-off

Rate is the number of bits spent, and Distortion is the difference from the original. The two always move in opposite directions. Spend more bits and distortion drops; save bits and distortion rises. The encoder's goal is either to 'minimize distortion within a given bit budget' or to 'minimize bits at a given quality.'

Bitrate (Rate) → Distortion → Older encoder Newer encoder (more efficient)
R-D curves — the better the encoder, the closer its curve sits to the origin (less distortion at the same bits)

The problem is how to combine two different units, 'bits' and 'distortion,' into one number you can compare. The answer is the Lagrange multiplier method.

The cost function an encoder actually computes
J = D + λ·R

  J : total cost. Pick the choice with the smallest value.
  D : distortion (usually SSD, the sum of squared errors against the original)
  R : number of bits that choice requires
  λ : the weight that balances bits against distortion (Lagrange multiplier)
An analogy

When grocery shopping you have to compare 'price' and 'taste,' which are different units. If you set an exchange rate (λ) like "1 point of taste = $1," you can rank every product by a single number: 'price + λ×(10 - taste score).' When λ is large (bits are expensive), you give up some taste and pick the cheap one; when λ is small (bits are cheap), you put taste first.

λ isn't a fixed value; it changes with the target QP (quantization parameter). The lower you set the quality (the higher the QP), the larger λ gets, and the more aggressively the encoder moves toward saving bits.

Where RDO is actually used

  • Mode decision — Intra or inter for this block, and which prediction direction? It computes J for each candidate and picks the minimum.
  • Block partitioning — Keep the 64×64 as is, or split it into four 32×32? Whether to split is also subject to RDO.
  • Quantization step selection — Rate control sets the bit budget for the whole frame, and RDO handles the fine-grained allocation per block.
  • Reference frame and motion vector selection — Which past frame to reference, and with which vector, also takes R and D into account together.
In the field — RDO is not in the standard

An important fact: RDO is not defined in the standard. A standard only says 'these modes exist'; 'which mode to pick' is up to the encoder. The difference in competitiveness among open-source encoders like x264, x265, and SVT-AV1 mostly comes from how sophisticated and fast an RDO they implement. "Full RDO" (actually encoding every candidate and comparing) is the most accurate but overwhelmingly slow, so most practical encoders prune candidates ahead of time with heuristics.

How file size and quality change when the same encoder spends more time searching (a slower preset) can be seen in our x265 preset measurement.

Rate-DistortionRate-distortion

The fundamental trade-off between bit usage (R) and quality loss (D).

Lagrangian cost (J = D + λR)Lagrangian cost

The encoder's core formula for combining R and D into one number to compare candidates.

RDORate-distortion optimization

Rate-Distortion Optimization. The encoder algorithm that finds the decision minimizing J.

QPQuantization parameter

Quantization Parameter. The value that sets how coarsely to quantize. Directly tied to λ.

Check yourself

In the Lagrangian cost function J = D + λR, how does the encoder behave when λ is set large?

Check yourself

Which statement about 'RDO' is correct?