Context-adaptive variable-length coding


Context-adaptive variable-length coding is a form of entropy coding used in H.264/MPEG-4 AVC video encoding. It is an inherently lossless compression technique, like almost all entropy-coders. In H.264/MPEG-4 AVC, it is used to encode residual, zig-zag order, blocks of transform coefficients. It is an alternative to context-based adaptive binary arithmetic coding. CAVLC requires considerably less processing to decode than CABAC, although it does not compress the data quite as effectively. CAVLC is supported in all H.264 profiles, unlike CABAC which is not supported in Baseline and Extended profiles.
CAVLC is used to encode residual, zig-zag ordered 4x4 blocks of transform coefficients. CAVLC is designed to take advantage of several characteristics of quantized 4x4 blocks:
Parameters that required to be encoded and transmitted include the following table:
ParametersDescription
Macroblock typePrediction method for each coded macroblock
Coded block patternIndicates which blocks within a macroblock contain coded coefficients
Quantizer parameter reference frameTransmitted as a delta value from the previous value of QP
Reference frame indexIdentify reference frame for inter prediction
Motion vectorTransmitted as a difference from predicted motion vector
Residual dataCoefficient data for each 4x4 or 2x2 block

CAVLC examples

ElementValueCode
coeff_tokenTotalCoeffs=5, T1s=30000100
T1 sign +0
T1 sign -1
T1 sign -1
Level +1 1
Level +3 0010
TotalZeros3111
run_beforeZerosLeft=3; run_before=110
run_beforeZerosLeft=2; run_before=01
run_beforeZerosLeft=2; run_before=01
run_beforeZerosLeft=2; run_before=101
run_beforeZerosLeft=1; run_before=1No code required; last coefficient.

CodeElementValueOutput array
0000100coeff_tokenTotal Coeffs=5, T1s=3Empty
0T1 sign+1
1T1 sign-−1, 1
1T1 sign-−1, −1, 1
1Level+11, −1, −1, 1
0010Level+33, 1, −1, −1, 1
111TotalZeros33, 1, −1, −1, 1
10run_before13, 1, −1, −1, 0, 1
1run_before03, 1, −1, −1, 0, 1
1run_before03, 1, −1, −1, 0, 1
01run_before13, 0, 1, −1, −1, 0, 1

In all following examples, we assume that table Num-VLC0 is used to encode coeff_token.

0, 3, 0, 1, −1, −1, 0, 1, 0…
TotalCoeffs = 5
TotalZeros = 3
T1s = 3
Encoding:
The transmitted bitstream for this block is 000010001110010111101101.
Decoding:
The output array is “built up” from the decoded values as shown below. Values added to the output array at each stage are underlined.
The decoder has inserted two zeros; however, TotalZeros is equal to 3 and so another 1 zero is inserted before the lowest coefficient, making the final output array: 0, 3, 0, 1, −1, −1, 0, 1