25
0000 0109 1000 0001 6742 0020 e900 800c
3200 0001 68ce 3c80 0000 0001 6588 801a

As far as I know, 0000 01 is the start prefix code to identify a NAL Unit. What does "09 .... " mean? Is it the header type byte?

faceclean
  • 3,781
  • 8
  • 39
  • 58

4 Answers4

36

0x000001 is the NAL start prefix code (it can also be 0x00000001, depends on the encoder implementation). 0x09 is 0b00001001, which means F=0, NRI = 0, and type is 0b01001. That particular type is an access unit delimiter. Notice that it is immediately followed by another NAL unit defined by 0x67, which is a NAL type of 7, which is the sequence parameter set.

There's also the picture parameter set:

00 0001 68...

...and the start of a keyframe:

0000 0001 65...

kidjan
  • 1,471
  • 14
  • 16
  • 1
    What does the 6 signify in 65? I know that keyframe start codes end in 65 but would like to know what 6 represents – Baba.S Nov 17 '19 at 00:50
15

The key reference to figuring out what kind of NAL you are looking at is http://www.itu.int/rec/T-REC-H.264-201304-S . Specifically, the table on page 63 (as of Jan 2014) lists all valid NAL types.

To figure out what you are looking out look at the first 4 bytes. If the NAL is in "Annex B" framing they will either be 00 00 01 or 00 00 00 01. This sequence is forbidden/suppressed within the H.264 bitstream so if you see it you know for certain that you are looking at the start of a NAL. The NAL type is the 5 low order bits after the 1. In code:

int nalType = p[2] == 1 ? (p[3] & 0x1f) : (p[4] & 0x1f);

Also in H.264 jargon IDR means I-frame and non-IDR means P or B frames.

With the above information we can look at the above stream and see an access unit delimiter, followed by an SPS, PPS, and first I-Frame.

Yaur
  • 7,333
  • 1
  • 25
  • 36
  • 6
    _Correction:_ All IDR frames are I-frames, but not all I-frames are IDR frames. IDR (Instantaneous Decoder Refresh) frames are special I-frames that not only contain a complete picture, but also indicates that no P/B-frame _after_ the IDR is allowed to reference a frame _before_ the IDR. – Iwillnotexist Idonotexist Mar 21 '17 at 05:31
  • What about the two bits above these 5? What do these mean? Oh, and is this framing scheme (with prefixes 0x000001 etc.) being used within MP4 file's samples in its "mdat" box? Because I don't see any such prefixes in one of my testing files… – SasQ Jun 25 '22 at 09:34
  • @SasQ MP4 files has AVCC format not the H.264 format. Mo4 files has NALU size as prefix of the NALU instead of 0x000001. For more information you can check onlinemp4parser.com – Mohammad Azam Jun 26 '22 at 10:41
10
    0000 0109 1000 0001 6742 0020 e900 800c
    3200 0001 68ce 3c80 0000 0001 6588 801a

-> 000001| 09 (AUD)| 10 | 000001 | 67(SPS) | xxxx (SPS data)
   xx | 000001 | 68 (PPS)| xxxx (PPS data)

AUD, SPS, PPS is type of NALU (Network Abstraction Layer Units) NALU have about 31 types.

09 AUD mean Access Unit Delimiter.

Access Unit Delimiter (AUD). An AUD is an optional NALU that can be use to delimit frames in an elementary stream. It is not required (unless otherwise stated by the container/protocol, like TS), and is often not included in order to save space, but it can be useful to finds the start of a frame without having to fully parse each NALU.

Check this answer for more information.

I also have a question about how to decode h264 stream (in iOS).

Community
  • 1
  • 1
Nhat Dinh
  • 3,378
  • 4
  • 35
  • 51
3

That defines the packet type. The format is:

+---------------+
|0|1|2|3|4|5|6|7|
+-+-+-+-+-+-+-+-+
|F|NRI|  Type   |
+---------------+

Are you sure this is an h.264 NAL header? From what you provided, this doesn't appear to be the header with the context you provided.

Matt
  • 509
  • 2
  • 5
  • 1
    I used a video stream analysis tool to analyze the video stream and it marks the boundary of frames. I picked up the beginning of an I frame. And the prefix code "00 00 01" also showed that this is a NAL. – faceclean Nov 06 '09 at 07:52
  • That prefix code doesn't show that it is a NAL because 0000 0109 is 8 bytes (64 bits) and no mangling of the first 16 bytes will give the prefix code indicating it's NAL. Remember, you're looking at a hex dump but all the specs and definitions refer to binary. – Matt Nov 06 '09 at 09:21
  • err, I failed at my math in the above comment, 0000 0109 is 4 bytes, not 8 (and 32 bits, not 64), but still will not mangle out to the prefix code you're looking for. – Matt Nov 06 '09 at 09:22
  • 3
    @Matt Actually the 000001 part of 00000109 does appear to be a valid NAL synchronization/prefix sequence – flamming_python Jul 02 '13 at 08:20