After the slice header comes the slice
data: the coded picture content, one coding tree unit (CTU) after another. Almost every
element here is coded with CABAC, context-adaptive binary arithmetic coding, written
ae(v), so none of them sits at a bit position that can be read directly. This
page gives the structure and the meaning of each element. How each element is binarised,
and the context models and initial probability tables of the arithmetic decoder (clause
9.3 of H.265), are not reproduced here.
Structure
slice_segment_data
repeat:
coding_tree_unit
sao (when SAO is on in the slice)
coding_quadtree (split recursively)
coding_unit
prediction_unit × 1, 2 or 4
pcm_sample (or)
palette_coding (or)
transform_tree (split recursively)
transform_unit
delta_qp, chroma_qp_offset
residual_coding (luma, Cb, Cr)
end_of_slice_segment_flag
end_of_subset_one_bit, byte_alignment (at each new tile or wavefront row)
rbsp_slice_segment_trailing_bits
CTUs follow tile scan: raster order inside each tile, tiles in raster order. The arithmetic decoder is initialised at the start of each slice segment and each tile, and after PCM samples. With wavefronts, each CTB row starts from the context state saved after the second CTB of the row above.
Slice segment data and CTU
| Name | Coding | Condition | Description |
|---|---|---|---|
coding_tree_unit() | per CTU | one CTB of luma and its chroma CTBs | |
end_of_slice_segment_flag | ae(v) | after each CTU | 1: this was the last CTU of the slice segment |
end_of_subset_one_bit | ae(v) | not the end, and the next CTU starts a tile or a wavefront row | always 1; followed by byte_alignment() |
Sample adaptive offset
| Name | Coding | Condition | Description |
|---|---|---|---|
sao_merge_left_flag | ae(v) | left CTB in the same slice and tile | 1: copy the SAO parameters of the CTB on the left |
sao_merge_up_flag | ae(v) | not merged left; upper CTB in the same slice and tile | 1: copy those of the CTB above |
sao_type_idx_luma | ae(v) | not merged, SAO on for luma | 0 not applied, 1 band offset, 2 edge offset |
sao_type_idx_chroma | ae(v) | not merged, SAO on for chroma | the same, shared by Cb and Cr |
sao_offset_abs[cIdx][rx][ry][i] | ae(v) | type not 0, four values | offset magnitudes; up to (1 << (min(bit depth, 10) − 5)) − 1, so 7 for 8-bit video |
sao_offset_sign[cIdx][rx][ry][i] | ae(v) | band offset, magnitude not 0 | 1: negative |
sao_band_position[cIdx][rx][ry] | ae(v) | band offset | first of the four consecutive bands (of 32) that get an offset |
sao_eo_class_luma, sao_eo_class_chroma | ae(v) | edge offset | 0 horizontal (0°), 1 vertical (90°), 2 diagonal 135°, 3 diagonal 45° |
For edge offset the four offsets apply to local minima, two kinds of edge, and local maxima; their signs are fixed (positive, positive, negative, negative) rather than coded.
Coding quadtree and coding unit
| Name | Coding | Condition | Description |
|---|---|---|---|
split_cu_flag[x0][y0] | ae(v) | block inside the picture and larger than the minimum | 1: split into four; a block crossing the picture edge is always split |
cu_transquant_bypass_flag | ae(v) | enabled in the PPS | 1: lossless coding unit, no transform, quantisation or loop filters |
cu_skip_flag[x0][y0] | ae(v) | P or B slice | 1: skipped: merge motion, no residual |
pred_mode_flag | ae(v) | P or B, not skipped | 0 inter, 1 intra; always intra in I slices |
palette_mode_flag[x0][y0] | ae(v) | palette enabled, intra, no larger than the largest transform | 1: palette coding |
part_mode | ae(v) | inter, or intra at the minimum size | see partition modes |
pcm_flag[x0][y0] | ae(v) | intra 2N×2N, PCM enabled, size in the PCM range | 1: raw samples follow |
pcm_alignment_zero_bit | f(1) | PCM, to the byte boundary | 0 |
pcm_sample_luma[i] | u(v) | PCM, one per luma sample | PcmBitDepthY bits each, raster order |
pcm_sample_chroma[i] | u(v) | PCM, not monochrome | all Cb samples, then all Cr, PcmBitDepthC bits each. The arithmetic decoder restarts after PCM data |
prev_intra_luma_pred_flag[x][y] | ae(v) | intra, per prediction block (1, or 4 for N×N) | 1: the mode is one of three most probable modes |
mpm_idx[x][y] | ae(v) | flag above is 1 | 0 to 2: which most probable mode |
rem_intra_luma_pred_mode[x][y] | ae(v) | flag above is 0 | 0 to 31: one of the 32 other modes |
intra_chroma_pred_mode[x][y] | ae(v) | intra, not monochrome; four times for N×N in 4:4:4 | see intra modes |
rqt_root_cbf | ae(v) | inter, not merge 2N×2N | 0: no residual for the coding unit; 1 when absent |
Partition modes
part_mode | Intra | Inter | Prediction blocks |
|---|---|---|---|
| 0 | PART_2Nx2N | PART_2Nx2N | one, the whole block |
| 1 | PART_NxN | PART_2NxN | intra: four squares; inter: two halves, top and bottom |
| 2 | PART_Nx2N | two halves, left and right | |
| 3 | PART_NxN | four squares (minimum size only, larger than 8 × 8) | |
| 4 | PART_2NxnU | top quarter, bottom three quarters | |
| 5 | PART_2NxnD | top three quarters, bottom quarter | |
| 6 | PART_nLx2N | left quarter, right three quarters | |
| 7 | PART_nRx2N | left three quarters, right quarter |
Modes 4 to 7 are the asymmetric partitions, allowed only with amp_enabled_flag.
Intra N×N sets IntraSplitFlag, which forces the first split of the transform
tree.
Prediction unit
| Name | Coding | Condition | Description |
|---|---|---|---|
merge_flag[x0][y0] | ae(v) | inter, not skipped | 1: motion copied from a merge candidate |
merge_idx[x0][y0] | ae(v) | skipped or merged, more than one candidate | 0 to MaxNumMergeCand − 1 |
inter_pred_idc[x0][y0] | ae(v) | B slice, not merged | 0 PRED_L0, 1 PRED_L1, 2 PRED_BI; bi-prediction is not allowed for 8 × 4 and 4 × 8 blocks. PRED_L0 when absent |
ref_idx_l0[x0][y0] | ae(v) | uses list 0, list longer than one | reference picture index in list 0 |
mvd_coding(x0, y0, 0) | uses list 0 | motion vector difference, see below | |
mvp_l0_flag[x0][y0] | ae(v) | uses list 0 | which of two motion vector predictors |
ref_idx_l1, mvd_coding(x0, y0, 1), mvp_l1_flag | uses list 1 | the same for list 1; the difference is not sent for bi-prediction when mvd_l1_zero_flag is set |
| Name | Coding | Description |
|---|---|---|
abs_mvd_greater0_flag[0], [1] | ae(v) | horizontal, vertical component is not zero |
abs_mvd_greater1_flag[0], [1] | ae(v) | magnitude is greater than 1 (only for non-zero components) |
abs_mvd_minus2[0], [1] | ae(v) | magnitude minus 2 |
mvd_sign_flag[0], [1] | ae(v) | 1: negative |
Motion vectors are in quarter luma samples, or whole samples when
use_integer_mv_flag is set.
Intra modes
Luma has 35 modes: 0 planar, 1 DC, and 2 to 34 angular, from bottom-left (2) through horizontal (10), diagonal top-left (18) and vertical (26) to top-right (34). Chroma picks one of five:
intra_chroma_pred_mode | Chroma mode |
|---|---|
| 0 | planar (0) |
| 1 | vertical (26) |
| 2 | horizontal (10) |
| 3 | DC (1) |
| 4 | the same as the luma mode |
When 0 to 3 would pick the same mode as luma, mode 34 is used instead. In 4:2:2 the chosen mode is then mapped through a further table to suit the half-width chroma.
Transform tree and transform unit
| Name | Coding | Condition | Description |
|---|---|---|---|
split_transform_flag[x0][y0][trafoDepth] | ae(v) | size between the minimum and maximum transform, depth below the limit | 1: split into four; inferred where the size forces it |
cbf_cb[x0][y0][trafoDepth] | ae(v) | chroma present and the parent’s Cb flag set | 1: the Cb block has non-zero coefficients; in 4:2:2 a second flag covers the lower block |
cbf_cr[x0][y0][trafoDepth] | ae(v) | the same | the same for Cr |
cbf_luma[x0][y0][trafoDepth] | ae(v) | leaf; not inferable | 1: the luma block has non-zero coefficients; 1 when absent |
tu_residual_act_flag[x0][y0] | ae(v) | colour transform enabled | 1: the adaptive colour transform applies to the residual |
cu_qp_delta_abs | ae(v) | QP deltas enabled, first coded block in the quantisation group | magnitude of the QP change |
cu_qp_delta_sign_flag | ae(v) | magnitude not 0 | 1: negative |
cu_chroma_qp_offset_flag | ae(v) | enabled in the slice, first in its group | 1: use an entry of the chroma QP offset list |
cu_chroma_qp_offset_idx | ae(v) | flag above is 1 and the list has more than one entry | which entry |
log2_res_scale_abs_plus1[c] | ae(v) | cross-component prediction (4:4:4) | 0: off; otherwise chroma residual is predicted from luma with scale 2this − 1 ÷ 8 |
res_scale_sign_flag[c] | ae(v) | value above not 0 | 1: negative scale |
For 4:2:0 and 4:2:2, a 4 × 4 luma block’s chroma is coded once, with the fourth of its four sibling blocks.
Residual coding
A transform block is coded as 4 × 4 sub-blocks, scanned backwards from the last significant coefficient, in diagonal, horizontal or vertical order (the latter two for some intra modes of 4 × 4 and 8 × 8 blocks).
| Name | Coding | Condition | Description |
|---|---|---|---|
transform_skip_flag[x0][y0][cIdx] | ae(v) | enabled, not bypass, small enough | 1: no transform; residual is coded in the sample domain |
explicit_rdpcm_flag[x0][y0][cIdx] | ae(v) | inter, enabled, skip or bypass | 1: residual DPCM |
explicit_rdpcm_dir_flag[x0][y0][cIdx] | ae(v) | flag above is 1 | 0 horizontal, 1 vertical |
last_sig_coeff_x_prefix, last_sig_coeff_y_prefix | ae(v) | position of the last non-zero coefficient (prefix) | |
last_sig_coeff_x_suffix, last_sig_coeff_y_suffix | ae(v) | prefix greater than 3 | the low bits of that position |
coded_sub_block_flag[xS][yS] | ae(v) | sub-blocks between the first and the last | 1: the 4 × 4 sub-block has non-zero coefficients |
sig_coeff_flag[xC][yC] | ae(v) | per position, unless inferable | 1: the coefficient is not zero |
coeff_abs_level_greater1_flag[n] | ae(v) | first 8 significant coefficients of the sub-block | 1: magnitude greater than 1 |
coeff_abs_level_greater2_flag[n] | ae(v) | first coefficient with the flag above set | 1: magnitude greater than 2 |
coeff_sign_flag[n] | ae(v) | each significant coefficient, except a hidden sign | 1: negative |
coeff_abs_level_remaining[n] | ae(v) | where the flags do not give the full magnitude | the rest of the magnitude, Rice and Exp-Golomb coded |
With sign data hiding, when the first and last significant coefficients of a sub-block are more than 3 scan positions apart, the sign of the first is not sent: it is negative when the sum of the magnitudes in the sub-block is odd.
Palette coding
Screen content coding only. A coding unit is coded as a palette of colours and a map of indices.
| Name | Coding | Description |
|---|---|---|
palette_predictor_run | ae(v) | run-length of which predictor entries are reused; 1 ends the list |
num_signalled_palette_entries | ae(v) | new entries sent for this block |
new_palette_entries[cIdx][i] | ae(v) | their component values |
palette_escape_val_present_flag | ae(v) | 1: some samples are escape-coded |
num_palette_indices_minus1 | ae(v) | number of index runs, minus 1 |
palette_idx_idc | ae(v) | the palette index of each run |
copy_above_indices_for_final_run_flag | ae(v) | 1: the last run copies from above |
palette_transpose_flag | ae(v) | 1: the traverse scan runs vertically |
copy_above_palette_indices_flag | ae(v) | 1: this run copies indices from the row above; 0: repeats one index |
palette_run_prefix, palette_run_suffix | ae(v) | run length, minus 1 |
palette_escape_val | ae(v) | quantised sample value of an escape-coded sample |