3

Does anyone know what does 0x21 and 0x61 means in h.264 encoded video stream?

I know that 0x01 means it's a b-frame and 0x41 means it's a p-frame. My encoded video gives me two 0x21 frame followed by one b-frame.

I 21 21 B 21 21 B...... 

What is this 0x21?

psanford
  • 5,580
  • 1
  • 26
  • 25
CGD
  • 259
  • 2
  • 3
  • 15
  • Do your hex values indicate the first byte of the NALU? – szatmary Mar 21 '14 at 17:15
  • @szatmary Please find the link below which contains the sequence of bytes. https://docs.google.com/document/d/1JcobN6NgK59nlyzcfY5FpnE6_ii7C6KvovXe1OBLmeE/pub This is the sequence of bytes i get. First one is SPS then PPS and then I frame , then I suppose P, P and B... How do I differentiate between frames. – CGD Mar 25 '14 at 05:37

2 Answers2

8

First point, a NALu is not the same than as a frame. A frame can contain more that 1 NALu (but not less). A frame can also be made up of more than one slice type. A single frame can have I, B and P slices. If it is an IDR frame, then EVERY slice of that frame must be IDR.

0x01 is NOT a B slice. it is a "Coded slice of a non-IDR picture". exactly like 0x21 and 0x61. It could be a I/B/P or p slice. you need to parse the slice_type to know more.

approxiblue
  • 6,982
  • 16
  • 51
  • 59
szatmary
  • 29,969
  • 8
  • 44
  • 57
  • 1
    Can you give any example or reference to parse the NAL uni t and find slice_type (I/P/B)? – santiago_apr1 Apr 01 '14 at 04:56
  • No I can not. The comment field will not allow me to type enough to answer. Please open another question. – szatmary Apr 01 '14 at 15:28
  • @szatmary Access units Delimeter, when present, can be used to identify start and end of the frame. When AUD is not present, what is the correct way to parse the starting and ending of a frame? Could you kindly explain. – Sandeep Oct 30 '17 at 03:02
  • You must parse every nalu until every macro-block is accounted for. – szatmary Oct 30 '17 at 04:16
5

From H.264 spec:

7.3.1 NAL unit syntax

  • forbidden_zero_bit - 1 bit - shall be equal to 0.
  • nal_ref_idc - 2 bits - not equal to 0 specifies that the content of the NAL unit contains a sequence parameter set [...]
  • nal_unit_type - 5 bits - specifies the type of RBSP data structure contained in the NAL unit [...]

0x21 and 0x61 make it NAL unit type 1 (Coded slice of a non-IDR picture) with different values for nal_ref_idc.

UPD. There is no one to one mapping of specific bit, esp. at fixed position from the beginning of the "frame" that says it's I/P/B frame. You will need to parse out the bitstream to read values per 7.4.3 Slice header semantics of H.264 spec (it is still doable in most cases since the value is real close to the beginning of the bitstream - check H.264 spec for details):

<code>slice_type</code>

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • So is this P frame or B frame? nal_unit_type will return 01 for all 4 combination. ( 0x01, 0x21, 0x41, 0x61 ) So how do we know whether packet is B fame , P frame or I frame? – CGD Mar 25 '14 at 04:55
  • 1
    This answer is incomplete. – szatmary Mar 25 '14 at 15:36