Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H264 NAL unit prefixes

I need some clarification on H264 NAL unit delimiter prefixes (00 00 00 01 and 00 00 01), I am using Intel Media SDK to generate a H264 and pack it into RTP. The issue is that so far I was looking only for 00 00 00 01 as a unit separator and basically was able to find only AUD,SPS,PPS and SEI units in the bitstream. Looking at the memory I saw that after the SEI there was a byte sequence 00 00 01 25 that could be a start of an IDR unit, but my search algorithm did not detect it because of a missing zero byte. Can anyone clarify the difference between 00 00 00 01 and 00 00 01 prefixes? Looking at Chromium code it seems that first unit as well as AUD, SPS, PPS, and SEI have an extra zero:

if (first_nal_in_this_access_unit ||
    IsAccessUnitBoundaryNal(nal_unit_type)) {
    output_size += 1;  // Extra zero_byte for these nal units
    first_nal_in_this_access_unit = false;
}

...

static bool IsAccessUnitBoundaryNal(int nal_unit_type) {
    // Check if this packet marks access unit boundary by checking the
    // packet type.
    if (nal_unit_type == 6 ||  // Supplemental enhancement information
        nal_unit_type == 7 ||  // Picture parameter set
        nal_unit_type == 8 ||  // Sequence parameter set
        nal_unit_type == 9 ||  // Access unit delimiter
        (nal_unit_type >= 14 && nal_unit_type <= 18)) {  // Reserved types
            return true;
        }
    return false;
}

1) I would assume I should look for both prefixes, but then I understand that I need to check the type of the next NAL unit in order to know the length of the current one (to know if the the prefix is 3 or 4 bytes and not consume a zero byte that could be an end of a previous NAL unit as the prefix).

2) Are PPS, SPS, and SEI sizes fixed? If so I could just jump to the end of the unit when looking for the next prefix.

I hope that someone who has had more experience with this can comment on the questions above.

like image 824
Rudolfs Bundulis Avatar asked May 07 '14 11:05

Rudolfs Bundulis


Video Answer


1 Answers

From H.264 spec, B.1.2 Byte stream NAL unit semantics:

enter image description here

zero_byte is a single byte equal to 0x00.

When any of the following conditions are fulfilled, the zero_byte syntax element shall be present.

  • the nal_unit_type within the nal_unit( ) is equal to 7 (sequence parameter set) or 8 (picture parameter set)
  • the byte stream NAL unit syntax structure contains the first NAL unit of an access unit in decoding order, as specified by subclause 7.4.1.2.3.
like image 91
Roman R. Avatar answered Oct 10 '22 11:10

Roman R.