Each NAL unit follows its start code and starts with a one-byte header. Its first three fields are the same in every NAL unit; types 14, 20 and 21 add a further two or three bytes of extension, which are never subject to emulation prevention.
NAL unit header
| Bit | Size | Name | Description |
|---|---|---|---|
| 7 | 1 | forbidden_zero_bit | always 0; 1 is a syntax violation |
| 6–5 | 2 | nal_ref_idc | 0 means the unit is not needed to reconstruct reference pictures and can be discarded; a non-zero value means it is |
| 4–0 | 5 | nal_unit_type | see NAL unit types |
So the first byte of an SPS is often 67: type 7 with a
nal_ref_idc of 3.
NAL unit types
| Type | Name | Contents |
|---|---|---|
| 0 | unspecified | |
| 1 | coded slice of a non-IDR picture | a slice, see the slice header |
| 2 | slice data partition A | headers and motion data of a partitioned slice |
| 3 | slice data partition B | intra residual data |
| 4 | slice data partition C | inter residual data |
| 5 | coded slice of an IDR picture | a slice of an instantaneous decoding refresh picture, where decoding can start |
| 6 | SEI | supplemental enhancement information |
| 7 | SPS | sequence parameter set |
| 8 | PPS | picture parameter set |
| 9 | AUD | access unit delimiter |
| 10 | end of sequence | no payload |
| 11 | end of stream | no payload |
| 12 | filler data | FF bytes |
| 13 | SPS extension | alpha plane information, see the SPS page |
| 14 | prefix NAL unit | carries SVC or MVC information for the unit after it |
| 15 | subset SPS | parameters for SVC and MVC layers |
| 16 | depth parameter set | |
| 17, 18 | reserved | |
| 19 | auxiliary slice | a slice of an auxiliary coded picture, such as alpha |
| 20 | coded slice extension | SVC or MVC slice |
| 21 | depth or 3D-AVC slice | coded slice extension for depth or 3D-AVC texture views |
| 22, 23 | reserved | |
| 24–31 | unspecified | free for system use. RTP uses them for aggregation and fragmentation packets (24 STAP-A, 25 STAP-B, 26 MTAP16, 27 MTAP24, 28 FU-A, 29 FU-B), which do not appear in a plain Annex B file |
For a plain (Annex A) decoder, types 1 to 5 are VCL units, carrying slice data, and all others are non-VCL, including 19, 20 and 21. Type 20 counts as VCL for SVC and MVC decoders, and 21 to 23 for MVC with depth and 3D-AVC decoders. A decoder may either decode types 13 and 19 or discard them.
NAL unit header extension
When nal_unit_type is 14 or 20, a further three bytes follow the header.
In the bit order given by RFC 6190, for SVC streams:
| Bits | Name | Description |
|---|---|---|
| 1 | svc_extension_flag | 1 for SVC; 0 selects the MVC layout. RFC 6190 calls this bit reserved |
| 1 | idr_flag | 1 for an IDR layer representation |
| 6 | priority_id | lower values mean higher priority |
| 1 | no_inter_layer_pred_flag | 1 means inter-layer prediction is not used |
| 3 | dependency_id | the inter-layer coding dependency level |
| 4 | quality_id | the quality level |
| 3 | temporal_id | the temporal layer |
| 1 | use_ref_base_pic_flag | 1 means only reference base pictures are used |
| 1 | discardable_flag | 1 means the unit is not used to decode higher dependency layers |
| 1 | output_flag | affects decoded picture output |
| 2 | reserved_three_2bits | binary 11 |
When svc_extension_flag is 0, the three bytes hold the MVC layout of
Annex G instead:
| Bits | Name | Description |
|---|---|---|
| 1 | svc_extension_flag | 0 |
| 1 | non_idr_flag | 0 for an IDR access unit of this view |
| 6 | priority_id | lower values mean higher priority |
| 10 | view_id | the view |
| 3 | temporal_id | the temporal layer |
| 1 | anchor_pic_flag | 1: an anchor picture, where decoding of the view can start |
| 1 | inter_view_flag | 1: other views may use this picture for inter-view prediction |
| 1 | reserved_one_bit | 1 |
Type 21 replaces svc_extension_flag with avc_3d_extension_flag.
When it is 1, a two-byte 3D-AVC extension (Annex I) follows the flag instead: 8 bits of
view_idx, then depth_flag, non_idr_flag, 3 bits of
temporal_id, anchor_pic_flag and inter_view_flag.
When it is 0, the MVC layout above follows. In a prefix NAL unit (type 14) these fields
apply to the NAL unit that comes after it.
Access unit delimiter
A type 9 unit marks the start of an access unit, the set of NAL units for one picture. Its payload is one field and the trailing bits:
| Name | Coding | Description |
|---|---|---|
primary_pic_type | u(3) | which slice types the picture may contain |
| Value | Slice types allowed |
|---|---|
| 0 | I |
| 1 | I, P |
| 2 | I, P, B |
| 3 | SI |
| 4 | SI, SP |
| 5 | I, SI |
| 6 | I, SI, P, SP |
| 7 | I, SI, P, SP, B |
These are Table 7-5 of H.264, which lists the slice_type values 0 to 9
allowed for each value.
Order of NAL units in an access unit
In an access unit an AUD comes first, when present. Any SPS, PPS and SEI units follow before the first slice of the primary coded picture. Then come the slices, and after them any redundant slices, auxiliary slices and filler. End of sequence and end of stream units come last.