Introduction
When entropy_coding_mode_flag is 1, every syntax element marked
ae(v) in the slice data is coded
by context-adaptive binary arithmetic coding (clause 9.3 of ITU-T H.264, 06/2026, version
16). The process has four parts: a binarisation turns the value into a string of bins; each
bin gets a context index ctxIdx; the arithmetic engine decodes the bin using
the probability state stored for that context; and the state is updated. The starting
states of all contexts are on the initial
values and 4:4:4 values pages. This
page gives the other three parts. The slice data starts after
cabac_alignment_one_bits, and the engine is initialised again after the PCM
samples of an I_PCM macroblock.
Arithmetic decoding engine (9.3.1.2, 9.3.3.2)
Initialisation. codIRange is 510 and codIOffset is
the next 9 bits, most significant first. The stream never produces an offset of 510 or 511.
DecodeBin(ctxIdx). A bypass bin uses DecodeBypass; ctxIdx 276
uses DecodeTerminate; all others use DecodeDecision.
DecodeDecision. Each context holds pStateIdx (0 to 63; 0 is an
LPS probability of 0.5, falling with the index) and valMPS.
qCodIRangeIdx = (codIRange >> 6) & 3andcodIRangeLPS = rangeTabLPS[pStateIdx][qCodIRangeIdx](Table 9-44, 9-25, 9-26).codIRange −= codIRangeLPS. IfcodIOffset ≥ codIRangethe bin is1 − valMPS,codIOffset −= codIRangeandcodIRange = codIRangeLPS; otherwise the bin isvalMPS.- State update (9-27): after an MPS,
pStateIdx = transIdxMPS[pStateIdx]; after an LPS, ifpStateIdxis 0 thenvalMPSflips, andpStateIdx = transIdxLPS[pStateIdx](Table 9-45). - Renormalisation: while
codIRange < 256,codIRangeis doubled andcodIOffset = (codIOffset << 1) | read_bits(1). After itcodIOffset < codIRangealways holds.
DecodeBypass. codIOffset = (codIOffset << 1) | read_bits(1);
if codIOffset ≥ codIRange the bin is 1 and codIOffset −= codIRange,
otherwise 0. No renormalisation.
DecodeTerminate. Used for end_of_slice_flag and for the bin
that signals I_PCM. codIRange −= 2. If codIOffset ≥ codIRange the
bin is 1, there is no renormalisation and decoding ends; the last bit read into
codIOffset is then 1 and, for end_of_slice_flag, is the
rbsp_stop_one_bit. Otherwise the bin is 0 and the engine renormalises.
Table 9-44: rangeTabLPS
Columns are qCodIRangeIdx 0 to 3. The same numbers, as far as rows 23, 31
and the transition table's ends were compared, are on the
H.265 CABAC page as Table 9-52.
| pState | 0 | 1 | 2 | 3 | pState | 0 | 1 | 2 | 3 | pState | 0 | 1 | 2 | 3 | pState | 0 | 1 | 2 | 3 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 128 | 176 | 208 | 240 | 16 | 62 | 76 | 90 | 104 | 32 | 27 | 33 | 39 | 45 | 48 | 12 | 14 | 17 | 20 |
| 1 | 128 | 167 | 197 | 227 | 17 | 59 | 72 | 86 | 99 | 33 | 26 | 31 | 37 | 43 | 49 | 11 | 14 | 16 | 19 |
| 2 | 128 | 158 | 187 | 216 | 18 | 56 | 69 | 81 | 94 | 34 | 24 | 30 | 35 | 41 | 50 | 11 | 13 | 15 | 18 |
| 3 | 123 | 150 | 178 | 205 | 19 | 53 | 65 | 77 | 89 | 35 | 23 | 28 | 33 | 39 | 51 | 10 | 12 | 15 | 17 |
| 4 | 116 | 142 | 169 | 195 | 20 | 51 | 62 | 73 | 85 | 36 | 22 | 27 | 32 | 37 | 52 | 10 | 12 | 14 | 16 |
| 5 | 111 | 135 | 160 | 185 | 21 | 48 | 59 | 69 | 80 | 37 | 21 | 26 | 30 | 35 | 53 | 9 | 11 | 13 | 15 |
| 6 | 105 | 128 | 152 | 175 | 22 | 46 | 56 | 66 | 76 | 38 | 20 | 24 | 29 | 33 | 54 | 9 | 11 | 12 | 14 |
| 7 | 100 | 122 | 144 | 166 | 23 | 43 | 53 | 63 | 72 | 39 | 19 | 23 | 27 | 31 | 55 | 8 | 10 | 12 | 14 |
| 8 | 95 | 116 | 137 | 158 | 24 | 41 | 50 | 59 | 69 | 40 | 18 | 22 | 26 | 30 | 56 | 8 | 9 | 11 | 13 |
| 9 | 90 | 110 | 130 | 150 | 25 | 39 | 48 | 56 | 65 | 41 | 17 | 21 | 25 | 28 | 57 | 7 | 9 | 11 | 12 |
| 10 | 85 | 104 | 123 | 142 | 26 | 37 | 45 | 54 | 62 | 42 | 16 | 20 | 23 | 27 | 58 | 7 | 9 | 10 | 12 |
| 11 | 81 | 99 | 117 | 135 | 27 | 35 | 43 | 51 | 59 | 43 | 15 | 19 | 22 | 25 | 59 | 7 | 8 | 10 | 11 |
| 12 | 77 | 94 | 111 | 128 | 28 | 33 | 41 | 48 | 56 | 44 | 14 | 18 | 21 | 24 | 60 | 6 | 8 | 9 | 11 |
| 13 | 73 | 89 | 105 | 122 | 29 | 32 | 39 | 46 | 53 | 45 | 14 | 17 | 20 | 23 | 61 | 6 | 7 | 9 | 10 |
| 14 | 69 | 85 | 100 | 116 | 30 | 30 | 37 | 43 | 50 | 46 | 13 | 16 | 19 | 22 | 62 | 6 | 7 | 8 | 9 |
| 15 | 66 | 80 | 95 | 110 | 31 | 29 | 35 | 41 | 48 | 47 | 12 | 15 | 18 | 21 | 63 | 2 | 2 | 2 | 2 |
Table 9-45: state transitions
| pStateIdx | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| transIdxLPS | 0 | 0 | 1 | 2 | 2 | 4 | 4 | 5 | 6 | 7 | 8 | 9 | 9 | 11 | 11 | 12 |
| transIdxMPS | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| pStateIdx | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| transIdxLPS | 13 | 13 | 15 | 15 | 16 | 16 | 18 | 18 | 19 | 19 | 21 | 21 | 22 | 22 | 23 | 24 |
| transIdxMPS | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
| pStateIdx | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
| transIdxLPS | 24 | 25 | 26 | 26 | 27 | 27 | 28 | 29 | 29 | 30 | 30 | 30 | 31 | 32 | 32 | 33 |
| transIdxMPS | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
| pStateIdx | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
| transIdxLPS | 33 | 33 | 34 | 34 | 35 | 35 | 35 | 36 | 36 | 36 | 37 | 37 | 37 | 38 | 38 | 63 |
| transIdxMPS | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 62 | 63 |
Binarisation processes (9.3.2)
| Name | Definition |
|---|---|
| U (unary) | a value n is n bins equal to 1 followed by a 0: 0 → 0, 1 → 10, 2 → 110, … |
TU (truncated unary), cMax | as U for values below cMax; the value cMax is cMax bins of 1 with no terminating 0 |
FL (fixed length), cMax | the value as an unsigned integer in Ceil(Log2(cMax + 1)) bits, with bin 0 the least significant bit |
UEGk, signedValFlag, uCoff | a prefix, TU of Min(uCoff, Abs(value)) with cMax = uCoff, then, only when Abs(value) ≥ uCoff, a suffix: sufS = Abs(value) − uCoff; while sufS ≥ (1 << k) write 1, subtract 1 << k and increment k; then write 0 and the k low bits of sufS, most significant first (9-6). A signed element then ends with a sign bin, 0 for positive, 1 for negative, when the value is not 0. The suffix and sign are bypass bins |
Elements with a prefix and a suffix (UEGk elements, mb_type,
coded_block_pattern) index binIdx from 0 in each part.
Binarisation and context offsets by element (Table 9-34)
| Element | Binarisation | maxBinIdxCtx | ctxIdxOffset |
|---|---|---|---|
mb_type (SI slices) | prefix 1 bin (0 for SI, 1 otherwise), suffix as I slices | prefix 0, suffix 6 | prefix 0, suffix 3 |
mb_type (I slices) | Table 9-36 | 6 | 3 |
mb_skip_flag (P, SP) | FL, cMax 1 | 0 | 11 |
mb_type (P, SP) | prefix and suffix, Table 9-37 and 9-36 | prefix 2, suffix 5 | prefix 14, suffix 17 |
sub_mb_type[] (P, SP) | Table 9-38 | 2 | 21 |
mb_skip_flag (B) | FL, cMax 1 | 0 | 24 |
mb_type (B) | prefix and suffix | prefix 3, suffix 5 | prefix 27, suffix 32 |
sub_mb_type[] (B) | Table 9-38 | 3 | 36 |
mvd_lX[][][0] | UEG3, signed, uCoff 9 | prefix 4, suffix na | prefix 40, suffix bypass |
mvd_lX[][][1] | UEG3, signed, uCoff 9 | prefix 4, suffix na | prefix 47, suffix bypass |
ref_idx_l0, ref_idx_l1 | U | 2 | 54 |
mb_qp_delta | U of the mapped value (below) | 2 | 60 |
intra_chroma_pred_mode | TU, cMax 3 | 1 | 64 |
prev_intra4x4_pred_mode_flag, prev_intra8x8_pred_mode_flag | FL, cMax 1 | 0 | 68 |
rem_intra4x4_pred_mode, rem_intra8x8_pred_mode | FL, cMax 7 | 0 | 69 |
mb_field_decoding_flag | FL, cMax 1 | 0 | 70 |
coded_block_pattern | prefix FL cMax 15, suffix TU cMax 2 | prefix 3, suffix 1 | prefix 73, suffix 77 |
coeff_sign_flag | FL, cMax 1 | 0 | bypass |
end_of_slice_flag | FL, cMax 1 | 0 | 276 (terminate) |
transform_size_8x8_flag | FL, cMax 1 | 0 | 399 |
The residual elements depend on ctxBlockCat and on whether the block is frame
or field coded. All are FL with cMax 1 and maxBinIdxCtx 0, except
coeff_abs_level_minus1, which is UEG0, unsigned, uCoff 14,
maxBinIdxCtx 1 for the prefix and bypass for the suffix. Their offsets:
| Element | ctxBlockCat < 5 | 5 | 6 to 8 | 9 | 10 to 12 | 13 |
|---|---|---|---|---|---|---|
coded_block_flag | 85 | 1012 | 460 | 1012 | 472 | 1012 |
significant_coeff_flag, frame | 105 | 402 | 484 | 660 | 528 | 718 |
significant_coeff_flag, field | 277 | 436 | 776 | 675 | 820 | 733 |
last_significant_coeff_flag, frame | 166 | 417 | 572 | 690 | 616 | 748 |
last_significant_coeff_flag, field | 338 | 451 | 864 | 699 | 908 | 757 |
coeff_abs_level_minus1 (prefix) | 227 | 426 | 952 | 708 | 982 | 766 |
The ctxBlockCat values (Table 9-42; maxNumCoeff in
brackets): 0 luma DC of Intra_16x16 (16), 1 luma AC of Intra_16x16 (15), 2 luma 4×4 (16),
3 chroma DC for 4:2:0 or 4:2:2 (4 × NumC8x8), 4 chroma AC (15), 5 luma 8×8
(64), 6 to 9 the Cb forms of 0, 1, 2 and 5 (4:4:4: DC 16, AC 15, 4×4 16, 8×8 64), 10 to 13
the Cr forms (the same order). Rows with the 8×8 categories (5, 9, 13) use the
coded_block_flag offset 1012 and the contexts of
ctxIdx 1012 to 1023.
Macroblock type bin strings
I slice mb_type (Table 9-36): bin 0 is 0 for I_NxN; bin 1 is the terminate bin
(ctxIdx 276), where 1 means I_PCM. SI slices
send the prefix bin 0 for SI itself; any other value sends 1 followed by this table indexed
by mb_type − 1. In P and SP slices an intra type sends the prefix 1
and then this table indexed by mb_type − 5; in B slices the prefix
111101 (Table 9-37) and this table indexed by mb_type − 23.
| mb_type | Bin string | mb_type | Bin string |
|---|---|---|---|
| 0 I_NxN | 0 | 13 I_16x16_0_0_1 | 1 0 1 0 0 0 |
| 1 I_16x16_0_0_0 | 1 0 0 0 0 0 | 14 I_16x16_1_0_1 | 1 0 1 0 0 1 |
| 2 I_16x16_1_0_0 | 1 0 0 0 0 1 | 15 I_16x16_2_0_1 | 1 0 1 0 1 0 |
| 3 I_16x16_2_0_0 | 1 0 0 0 1 0 | 16 I_16x16_3_0_1 | 1 0 1 0 1 1 |
| 4 I_16x16_3_0_0 | 1 0 0 0 1 1 | 17 I_16x16_0_1_1 | 1 0 1 1 0 0 0 |
| 5 I_16x16_0_1_0 | 1 0 0 1 0 0 0 | 18 I_16x16_1_1_1 | 1 0 1 1 0 0 1 |
| 6 I_16x16_1_1_0 | 1 0 0 1 0 0 1 | 19 I_16x16_2_1_1 | 1 0 1 1 0 1 0 |
| 7 I_16x16_2_1_0 | 1 0 0 1 0 1 0 | 20 I_16x16_3_1_1 | 1 0 1 1 0 1 1 |
| 8 I_16x16_3_1_0 | 1 0 0 1 0 1 1 | 21 I_16x16_0_2_1 | 1 0 1 1 1 0 0 |
| 9 I_16x16_0_2_0 | 1 0 0 1 1 0 0 | 22 I_16x16_1_2_1 | 1 0 1 1 1 0 1 |
| 10 I_16x16_1_2_0 | 1 0 0 1 1 0 1 | 23 I_16x16_2_2_1 | 1 0 1 1 1 1 0 |
| 11 I_16x16_2_2_0 | 1 0 0 1 1 1 0 | 24 I_16x16_3_2_1 | 1 0 1 1 1 1 1 |
| 12 I_16x16_3_2_0 | 1 0 0 1 1 1 1 | 25 I_PCM | 1 1 |
The name I_16x16_a_b_c is the prediction mode a, the chroma coded
block pattern b and the luma flag c (Table 7-11).
P, SP and B macroblock types (Table 9-37; in P and SP type 4, P_8x8ref0, never occurs):
| Slice | mb_type | Bin string | mb_type | Bin string |
|---|---|---|---|---|
| P, SP | 0 P_L0_16x16 | 0 0 0 | 2 P_L0_L0_8x16 | 0 1 0 |
| 1 P_L0_L0_16x8 | 0 1 1 | 3 P_8x8 | 0 0 1 | |
| 5 to 30 intra | 1 then Table 9-36 | |||
| B | 0 B_Direct_16x16 | 0 | 12 B_L0_Bi_16x8 | 1 1 1 0 0 0 0 |
| 1 B_L0_16x16 | 1 0 0 | 13 B_L0_Bi_8x16 | 1 1 1 0 0 0 1 | |
| 2 B_L1_16x16 | 1 0 1 | 14 B_L1_Bi_16x8 | 1 1 1 0 0 1 0 | |
| 3 B_Bi_16x16 | 1 1 0 0 0 0 | 15 B_L1_Bi_8x16 | 1 1 1 0 0 1 1 | |
| 4 B_L0_L0_16x8 | 1 1 0 0 0 1 | 16 B_Bi_L0_16x8 | 1 1 1 0 1 0 0 | |
| 5 B_L0_L0_8x16 | 1 1 0 0 1 0 | 17 B_Bi_L0_8x16 | 1 1 1 0 1 0 1 | |
| 6 B_L1_L1_16x8 | 1 1 0 0 1 1 | 18 B_Bi_L1_16x8 | 1 1 1 0 1 1 0 | |
| 7 B_L1_L1_8x16 | 1 1 0 1 0 0 | 19 B_Bi_L1_8x16 | 1 1 1 0 1 1 1 | |
| 8 B_L0_L1_16x8 | 1 1 0 1 0 1 | 20 B_Bi_Bi_16x8 | 1 1 1 1 0 0 0 | |
| 9 B_L0_L1_8x16 | 1 1 0 1 1 0 | 21 B_Bi_Bi_8x16 | 1 1 1 1 0 0 1 | |
| 10 B_L1_L0_16x8 | 1 1 0 1 1 1 | 22 B_8x8 | 1 1 1 1 1 1 | |
| 11 B_L1_L0_8x16 | 1 1 1 1 1 0 | 23 to 48 intra | 1 1 1 1 0 1 then Table 9-36 |
Sub-macroblock types (Table 9-38):
| Slice | sub_mb_type | Bin string | sub_mb_type | Bin string |
|---|---|---|---|---|
| P, SP | 0 P_L0_8x8 | 1 | 2 P_L0_4x8 | 0 1 1 |
| 1 P_L0_8x4 | 0 0 | 3 P_L0_4x4 | 0 1 0 | |
| B | 0 B_Direct_8x8 | 0 | 7 B_L1_4x8 | 1 1 1 0 0 0 |
| 1 B_L0_8x8 | 1 0 0 | 8 B_Bi_8x4 | 1 1 1 0 0 1 | |
| 2 B_L1_8x8 | 1 0 1 | 9 B_Bi_4x8 | 1 1 1 0 1 0 | |
| 3 B_Bi_8x8 | 1 1 0 0 0 | 10 B_L0_4x4 | 1 1 1 0 1 1 | |
| 4 B_L0_8x4 | 1 1 0 0 1 | 11 B_L1_4x4 | 1 1 1 1 0 | |
| 5 B_L0_4x8 | 1 1 0 1 0 | 12 B_Bi_4x4 | 1 1 1 1 1 | |
| 6 B_L1_8x4 | 1 1 0 1 1 |
coded_block_pattern. The prefix is CodedBlockPatternLuma as
4 bins (FL, cMax 15; bin k is bit k, the 8×8 block with
luma8x8BlkIdx k). When ChromaArrayType is neither 0 nor 3
a TU suffix with cMax 2 follows for CodedBlockPatternChroma, always, whatever
the prefix. mb_qp_delta. The signed value is mapped as in the se(v) code
(Table 9-3: 0 → 0, 1 → 1, −1 → 2, 2 → 3, −2 → 4, …) and sent in U binarisation.
Choosing the context index (9.3.3.1)
ctxIdx = ctxIdxOffset + ctxIdxInc. For the elements of Table 9-39,
ctxIdxInc depends on binIdx; every bin beyond
maxBinIdxCtx uses the context of maxBinIdxCtx. A value with
several entries in the table is chosen by the clause named. For the residual elements
ctxIdx = ctxIdxOffset + ctxIdxBlockCatOffset(ctxBlockCat) + ctxIdxInc.
Bins marked bypass use no context, and ctxIdx 276 is decoded with
DecodeTerminate.
Table 9-39: ctxIdxInc by bin
| Offset | Element and part | bin 0 | bin 1 | bin 2 | bin 3 | bin 4 | bin 5 | bin ≥ 6 |
|---|---|---|---|---|---|---|---|---|
| 0 | mb_type SI prefix | 0, 1, 2 (A) | na | na | na | na | na | na |
| 3 | mb_type I (and SI suffix) | 0, 1, 2 (A) | 276 | 3 | 4 | 5 or 6 (B) | 6 or 7 (B) | 7 |
| 11 | mb_skip_flag P | 0, 1, 2 (C) | na | na | na | na | na | na |
| 14 | mb_type P prefix | 0 | 1 | 2 or 3 (B) | na | na | na | na |
| 17 | mb_type P suffix | 0 | 276 | 1 | 2 | 2 or 3 (B) | 3 | 3 |
| 21 | sub_mb_type P | 0 | 1 | 2 | na | na | na | na |
| 24 | mb_skip_flag B | 0, 1, 2 (C) | na | na | na | na | na | na |
| 27 | mb_type B prefix | 0, 1, 2 (A) | 3 | 4 or 5 (B) | 5 | 5 | 5 | 5 |
| 32 | mb_type B suffix | 0 | 276 | 1 | 2 | 2 or 3 (B) | 3 | 3 |
| 36 | sub_mb_type B | 0 | 1 | 2 or 3 (B) | 3 | 3 | 3 | na |
| 40 | mvd_lX horizontal prefix | 0, 1, 2 (D) | 3 | 4 | 5 | 6 | 6 | 6 |
| 47 | mvd_lX vertical prefix | 0, 1, 2 (D) | 3 | 4 | 5 | 6 | 6 | 6 |
| 54 | ref_idx_lX | 0 to 3 (E) | 4 | 5 | 5 | 5 | 5 | 5 |
| 60 | mb_qp_delta | 0, 1 (F) | 2 | 3 | 3 | 3 | 3 | 3 |
| 64 | intra_chroma_pred_mode | 0, 1, 2 (G) | 3 | 3 | na | na | na | na |
| 68 | prev_intra_pred_mode_flag | 0 | na | na | na | na | na | na |
| 69 | rem_intra_pred_mode | 0 | 0 | 0 | na | na | na | na |
| 70 | mb_field_decoding_flag | 0, 1, 2 (H) | na | na | na | na | na | na |
| 73 | coded_block_pattern prefix | 0 to 3 (I) | 0 to 3 (I) | 0 to 3 (I) | 0 to 3 (I) | na | na | na |
| 77 | coded_block_pattern suffix | 0 to 3 (J) | 4 to 7 (J) | na | na | na | na | na |
| 276 | end_of_slice_flag | 0 | na | na | na | na | na | na |
| 399 | transform_size_8x8_flag | 0, 1, 2 (K) | na | na | na | na | na | na |
"(B)" means the value comes from the earlier bins (Table 9-41, below). In the rows for
offsets 17 and 32 bin 1 is the I_PCM terminate bin of the intra suffix, so the table's
ctxIdx 276 stands in the place of a context.
Table 9-41: ctxIdxInc from earlier bins
| ctxIdxOffset | binIdx | ctxIdxInc |
|---|---|---|
| 3 | 4 | (b3 != 0) ? 5 : 6 |
| 3 | 5 | (b3 != 0) ? 6 : 7 |
| 14 | 2 | (b1 != 1) ? 2 : 3 |
| 17 | 4 | (b3 != 0) ? 2 : 3 |
| 27 | 2 | (b1 != 0) ? 4 : 5 |
| 32 | 4 | (b3 != 0) ? 2 : 3 |
| 36 | 2 | (b1 != 0) ? 2 : 3 |
Neighbour rules
Neighbours A (left) and B (above) are the macroblocks or blocks found by the derivation
processes of clause 6.4. Unavailable means outside the picture or slice. For
clauses (A) to (K), condTermFlagN is as follows; ctxIdxInc is
their sum unless stated.
| Element (clause) | condTermFlagN is 0 when | ctxIdxInc |
|---|---|---|
(C) mb_skip_flag (9.3.3.1.1.1) | N is unavailable or skipped (in MBAFF, the field decoding flag is inferred first if not yet decoded); otherwise 1 | A + B (9-7) |
(H) mb_field_decoding_flag (9.3.3.1.1.2) | N (a macroblock pair) is unavailable or a frame macroblock pair; for a skipped pair the inferred flag is used | A + B (9-8) |
(A) mb_type (9.3.3.1.1.3) | N is unavailable; or for offset 0, N is SI; for offset 3, N is I_NxN; for offset 27, N is B_Skip or B_Direct_16x16 | A + B (9-9) |
(I) coded_block_pattern luma bin (9.3.3.1.1.4) | for the 8×8 block binIdx and its neighbour block N: N is unavailable, N is I_PCM, N is another macroblock that is not skipped and has the neighbouring block's coded bit set, or N is the current macroblock and the earlier bin for that block is set. Otherwise 1 | A + 2 × B (9-10) |
(J) coded_block_pattern chroma bin | 1 when N is available and I_PCM. Otherwise 0 when N is unavailable or skipped, or when for bin 0 N has CodedBlockPatternChroma 0, or for bin 1 N has a value other than 2; otherwise 1 | A + 2 × B + (4 when bin 1) (9-11) |
(F) mb_qp_delta (9.3.3.1.1.5) | one preceding macroblock in decoding order, prevMbAddr: ctxIdxInc is 0 when it is unavailable (first of the slice), skipped, I_PCM, has mb_qp_delta 0, or is not Intra_16x16 and has both coded block pattern values 0; otherwise 1 | 0 or 1 |
(E) ref_idx_lX (9.3.3.1.1.6) | N is unavailable, skipped, intra, B_Skip or B_Direct_16x16 or the partition does not use list X (a sub-macroblock type is checked per partition), or refIdxZeroFlagN (the reference index of the neighbouring partition is 0; in MBAFF, a frame macroblock next to a field macroblock treats an index of 1 as 0, 9-12, 9-13) | A + 2 × B (9-14) |
(D) mvd_lX (9.3.3.1.1.7) | uses absMvdCompN: 0 when N is unavailable, skipped, intra or not predicted from list X; otherwise the absolute value of the neighbouring partition's mvd component, doubled for the vertical component of a field neighbour when the current macroblock is a frame one and halved for the reverse (9-15 to 9-17) | sum of A and B > 32: 2; > 2: 1; otherwise 0 (a single component above 32 also gives 2) |
(G) intra_chroma_pred_mode (9.3.3.1.1.8) | N is unavailable, inter, I_PCM or has intra_chroma_pred_mode 0 | A + B (9-18) |
(K) transform_size_8x8_flag (9.3.3.1.1.10) | N is unavailable or has the flag 0 | A + B (9-20) |
coded_block_flag (9.3.3.1.1.9) | see below | A + 2 × B (9-19) |
coded_block_flag. For the neighbouring transform block of the same kind
(transBlockN): the luma, Cb or Cr DC block of an Intra_16x16 neighbour
(ctxBlockCat 0, 6, 10); for 4×4 and AC categories the block with the same index
in the neighbour when its coded block pattern bit is set, taking the 8×8 block when the
neighbour used the 8×8 transform; the chroma DC block when
CodedBlockPatternChroma is not 0; chroma AC when it is 2; for the 8×8 categories
(5, 9, 13) the 8×8 block when the neighbour used the 8×8 transform. Skipped and I_PCM
neighbours have none. Then condTermFlagN is 0 when N is unavailable and the
current macroblock is inter, when N is available but has no such block and is not I_PCM, or
when the current macroblock is intra with constrained_intra_pred_flag 1, N is
inter and data partitioning is in use. It is 1 when N is unavailable and the current
macroblock is intra, or N is I_PCM. Otherwise it is the coded_block_flag that was
decoded for transBlockN.
Residual contexts (9.3.3.1.3)
ctxIdxBlockCatOffset (Table 9-40), by ctxBlockCat:
| Element | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
coded_block_flag | 0 | 4 | 8 | 12 | 16 | 0 | 0 | 4 | 8 | 4 | 0 | 4 | 8 | 8 |
significant_coeff_flag, last_significant_coeff_flag | 0 | 15 | 29 | 44 | 47 | 0 | 0 | 15 | 29 | 0 | 0 | 15 | 29 | 0 |
coeff_abs_level_minus1 | 0 | 10 | 20 | 30 | 39 | 0 | 0 | 10 | 20 | 0 | 0 | 10 | 20 | 0 |
significant_coeff_flag and last_significant_coeff_flag.
ctxIdxInc = levelListIdx (0 to maxNumCoeff − 2) for categories
other than 3, 5, 9 and 13 (9-21); for category 3,
Min(levelListIdx ÷ NumC8x8, 2) (9-22); for the 8×8 categories 5, 9 and 13,
Table 9-43. The list index is the position in the scan of the coefficient levels, and the
last coefficient of a block needs no flag.
| idx | sig frame | sig field | last | idx | sig frame | sig field | last | idx | sig frame | sig field | last |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 21 | 3 | 11 | 2 | 42 | 14 | 10 | 4 |
| 1 | 1 | 1 | 1 | 22 | 6 | 12 | 2 | 43 | 10 | 10 | 4 |
| 2 | 2 | 1 | 1 | 23 | 7 | 11 | 2 | 44 | 9 | 8 | 4 |
| 3 | 3 | 2 | 1 | 24 | 7 | 9 | 2 | 45 | 8 | 13 | 4 |
| 4 | 4 | 2 | 1 | 25 | 7 | 9 | 2 | 46 | 6 | 13 | 4 |
| 5 | 5 | 3 | 1 | 26 | 8 | 10 | 2 | 47 | 11 | 9 | 4 |
| 6 | 5 | 3 | 1 | 27 | 9 | 10 | 2 | 48 | 12 | 9 | 5 |
| 7 | 4 | 4 | 1 | 28 | 10 | 8 | 2 | 49 | 13 | 10 | 5 |
| 8 | 4 | 5 | 1 | 29 | 9 | 11 | 2 | 50 | 11 | 10 | 5 |
| 9 | 3 | 6 | 1 | 30 | 8 | 12 | 2 | 51 | 6 | 8 | 5 |
| 10 | 3 | 7 | 1 | 31 | 7 | 11 | 2 | 52 | 9 | 13 | 6 |
| 11 | 4 | 7 | 1 | 32 | 7 | 9 | 3 | 53 | 14 | 13 | 6 |
| 12 | 4 | 7 | 1 | 33 | 6 | 9 | 3 | 54 | 10 | 9 | 6 |
| 13 | 4 | 8 | 1 | 34 | 11 | 10 | 3 | 55 | 9 | 9 | 6 |
| 14 | 5 | 4 | 1 | 35 | 12 | 10 | 3 | 56 | 11 | 10 | 7 |
| 15 | 5 | 5 | 1 | 36 | 13 | 8 | 3 | 57 | 12 | 10 | 7 |
| 16 | 4 | 6 | 2 | 37 | 11 | 11 | 3 | 58 | 13 | 14 | 7 |
| 17 | 4 | 9 | 2 | 38 | 6 | 12 | 3 | 59 | 11 | 14 | 7 |
| 18 | 4 | 10 | 2 | 39 | 7 | 11 | 3 | 60 | 14 | 14 | 8 |
| 19 | 4 | 10 | 2 | 40 | 8 | 9 | 4 | 61 | 10 | 14 | 8 |
| 20 | 3 | 8 | 2 | 41 | 9 | 9 | 4 | 62 | 12 | 14 | 8 |
coeff_abs_level_minus1. Let numDecodAbsLevelEq1 and
numDecodAbsLevelGt1 count the levels already decoded in the same block with
absolute value 1 and above 1. Bin 0:
ctxIdxInc = (numDecodAbsLevelGt1 != 0) ? 0 : Min(4, 1 + numDecodAbsLevelEq1)
(9-23). Other prefix bins:
ctxIdxInc = 5 + Min(4 − (ctxBlockCat == 3 ? 1 : 0), numDecodAbsLevelGt1)
(9-24). The UEG0 suffix and coeff_sign_flag are bypass bins.
Not covered on this page
The informative arithmetic encoder (9.3.4), the flowchart figures, and the macroblock neighbour derivations of clause 6.4 that the context rules call (availability, MBAFF neighbours). The alternative CABAC parsing of the scalable and 3D extensions has its added contexts on the SVC and 3D-AVC pages. Source: ITU-T H.264 (06/2026, version 16), clause 9.3.