Ch. 2 · Principles of Compression

한국어日本語
6 min

Context Modeling in CABAC: How Codecs Predict Probabilities

Why CABAC is so efficient: not arithmetic coding alone, but context models that update each symbol's probability on the fly from neighboring blocks.

In the last lesson we said arithmetic coding reflects probabilities precisely. But where do those probabilities come from? If you use a fixed table, you miss statistics that change from scene to scene, even from block to block.

The core idea

Context modeling is a technique that 'estimates the probability of the value being coded right now from surrounding information.' For example, 'if the left and upper blocks both had zero residual, the current block is probably zero too' — you switch probability tables depending on the context.

Above residual=0 Left residual=0 Current ? Context = "both 0" P(0) ≈ 0.94
A context selection example — the state of neighboring blocks picks 'the probability that the current bit is 0'

When you do arithmetic coding with the probability obtained this way, the more the prediction is right (that is, the more 0 actually shows up), the fewer bits you spend. And as coding proceeds, the coder observes the real statistics and updates the probabilities adaptively — that's the 'Adaptive' in CABAC.

CodecWhat the context reflects
H.264 CABACWhether neighboring macroblocks have coefficients, their modes, QP, etc. — about 460 contexts
HEVC CABACFiner-grained by transform size and depth, about 154 contexts
AV1 (multi-symbol arithmetic coding)Codes multi-symbol (M-ary) values directly instead of binary, with much finer contexts
VVCMore refined context initialization and switching rules than HEVC
In the field

An entropy coder is inherently sequential. To decode one bit you need the preceding state (the probabilities), so it's hard to parallelize. HEVC's tiles and WPP (Wavefront Parallel Processing) are the answer to exactly this problem: how to untangle CABAC's serial nature across multiple hardware cores (covered in Chapter 6).

Context modelingContext modeling

A technique for estimating a symbol's probability from surrounding information.

Adaptive probabilityAdaptive probability

A probability that is updated on the fly according to the statistics actually observed.

BinBin

The binary unit that gets arithmetic-coded in CABAC. A syntax value is binarized into several bins.

Check yourself

What role does the 'context' play in CABAC?