Ch. 3 · Anatomy of a Hybrid Codec

한국어日本語
7 min

Quantization and QP in Video Coding: Where the Loss Happens

Up to the transform, nothing is lost (rounding aside). Quantization is the only lossy step. See how QP sets quality and bitrate, and how CQP, CRF and ABR differ.

The steps so far (prediction, transform) only rearranged information; they didn't discard any. Quantization is the only step in the codec pipeline that deliberately throws information away.

The essence of quantization
Quantization:          level = round( coefficient / Qstep )
Inverse quantization:  coefficient' = level × Qstep

The larger the Qstep → the more values collapse into the same level
                     → compresses better, but the reconstruction error (distortion) also grows
12 13 14 15 16 Original coefficient values (fine-grained) Represented by a single "14" After quantization (12–16 all become 14)
Quantization = swapping a fine ruler for a coarse one. Many original values collapse into a single representative value

QP — Quantization Parameter

Rather than handle Qstep directly, codecs control it indirectly through an integer called the QP (quantization parameter). As QP grows, so does Qstep (coarser quantization). H.264/HEVC were designed so that every time QP increases by 6, Qstep exactly doubles — a logarithmic scale, which also ties in with human brightness perception (the logarithmic response from Chapter 1).

QP range (e.g., HEVC 0–51)What it feels like
0 ~ 18Close to lossless, very large files
19 ~ 28High-quality streaming, broadcast masters
29 ~ 36Typical distribution streaming
37 and aboveLow bandwidth, clearly visible quality loss

Dead-zone quantization

Codecs include a dead zone that turns small coefficients near 0 into exactly 0. As you learned in Chapter 2, the residual distribution concentrates its probability near 0 (a Laplacian distribution), so boldly zeroing small values lets entropy coding handle the resulting runs of consecutive zeros extremely efficiently.

The link to rate-distortion — quantization determines both R and D

Connection to Chapter 2

QP (quantization) is the knob that directly decides where you land on the R-D curve from Chapter 2. Lower the QP and D (distortion) falls but R (bits) rises; raise the QP and the opposite happens. Rate control algorithms adjust QP in real time, frame by frame and even block by block, to hit a target bitrate (or quality).

In practice — CQP, CRF, ABR

In practice you must tell three QP control modes apart. CQP (Constant QP) fixes the QP — file size is unpredictable, so it's for testing. CRF (Constant Rate Factor, in x264/x265/libaom) keeps 'perceived quality constant' by adjusting QP automatically with scene complexity — the most common choice for VOD delivery. ABR (Average Bitrate) adjusts QP to hit a target average bitrate — essential where bandwidth is fixed, such as broadcast. Which to use comes down to 'match the quality, or match the file size/bandwidth?'

How much file size varies with the content at the same CRF can be seen in our CRF size-and-quality measurement. The bitrate at x264 CRF 28 was about 2,490 kbps for one clip and about 11,623 kbps for another. To pick a CRF for the quality you want, try the CRF recommender. Which to hold fixed — CRF, 2-pass, or CQ — continues in Chapter 18.

QuantizationQuantization

The only step in the codec pipeline that deliberately discards information.

QPQuantization Parameter

An integer that indirectly controls the quantization step size. A larger value means coarser quantization.

Dead zoneDead zone

A quantization interval that turns small coefficients near 0 into exactly 0.

Rate controlRate control

An algorithm that dynamically adjusts QP to hit a target bitrate or quality.

CRF / ABR / CQPConstant Rate Factor / Average Bitrate / Constant QP

Three representative rate control modes used in practice.

Check yourself

Which is the only step in the codec pipeline that 'deliberately discards information'?

Check yourself

Which rate control mode is commonly used for VOD (video on demand) delivery when you want to keep perceived quality constant?