Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect H264/AVC ISO/IEC 14496-15 AVCDecoderConfigurationRecord?

Some historic background: I'm currently working with Wowza and attempting to decode the AMFPackets that come from the IMediaStream. The video packets will have a 5-byte header and the first packet is the codec configuration.

So far in my inspecting the codec configuration matches the ISO/IEC 14496-15 AVCDecoderConfigurationRecord layout. However, I'm having trouble decoding the SPS and PPS units.

The codec config packet including the 5-byte header:

17 00 00 00 00 01 4D 00 15 03 01 00 2F 67 4D 40 15 96 52 02 83 F6 02 A1 00 00 03 00 01 00 00 03 00 28 E0 60 03 0D 40 00 49 3E 7F 18 E3 03 00 18 6A 00 02 49 F3 F8 C7 0E D0 B1 68 90 01 00 04 68 EB 73 52

Flash/Wowza-specific first is the header:

17 00 00 00 00

  • 17 = 10111 = H.264 K frame
  • 00 = 0 = codec config packet
  • 000000 = 0 = start time 0

Next is the AVCDecoderConfigurationRecord (hex = decimal):

  • configurationVersion: 01 = 1
  • AVCProfileIndication: 4D = 77 (Main)
  • profile_compatibility: 00 = 0
  • AVCLevelIndication: 15 = 21 (2.1)
  • 6 bits reserved + lengthSizeMinusOne: 03 = 00000011 = 3 (4 bytes)
  • 3 bits reserved + numOfSequenceParameterSets: 01 = 0001 = 1
  • sequenceParameterSetLength: 002F = (47 bytes)
  • (SPS record 47 bytes long)
  • numOfPictureParameterSets: 01 = 1
  • pictureParameterSetLength: 0004 = (4 bytes)
  • (PPS record 4 bytes long)
  • (end)

SPS record (47 bytes):

67 4D 40 15 96 52 02 83 F6 02 A1 00 00 03 00 01 00 00 03 00 28 E0 60 03 0D 40 00 49 3E 7F 18 E3 03 00 18 6A 00 02 49 F3 F8 C7 0E D0 B1 68 90

Assuming this is a NAL unit containing SPS type: (Using ITU-T H.264 06/2011 7.3.1 NAL unit syntax)

  • First byte: 67 = 1100111
  • forbidden_zero_bit: 1 (Oops, forbidden 0 bit set to 1?)
  • nal_ref_idc: 2
  • nal_unit_type: 0111 = 7 (SPS)

Assuming the SPS payload follow: (Using ITU-T H.264 06/2011 7.3.2.1.1 Sequence parameter set data syntax)

  • profile_idc: 4D = 77 (Main, matches)
  • constraints + 2 bits reserved (equal to 0): 40 = 1000000 (Looks fine)
  • level_idc: 15 (2.1, matches)

Assuming this is only a SPS: (Using ITU-T H.264 06/2011 7.3.2.1.1 Sequence parameter set data syntax)

  • profile_idc: 67 = 103 (I think this should be 77 like AVCProfileIndication?)
  • constraints + 2 bits reserved (equal to 0): 4D = 1001101 (Uh oh, reserved bit set?)
  • level_idc: 77 (Shouldn't this be 21 like AVCLevelIndication?)

It looks like it's the former NAL unit header + SPS record, and I doubt it's bad data because every captured config packet is the same, but what throws me off is why is the forbidden 0 bit set to 1?

Thanks

like image 218
Rob Olmos Avatar asked Jun 23 '12 19:06

Rob Olmos


1 Answers

I found the problem... too much staring at 1's and 0's and you'll miss one (pun intended).

67 4D 40 15...

Assuming this is a NAL unit containing SPS type: (Using ITU-T H.264 06/2011 7.3.1 NAL unit syntax)

First byte: 67 = 1100111

This is wrong because 1100111 is only 7-bits. I did the conversion using MS Calculator and it stripped the leading 0. The correct binary is 01100111, and there's the forbidden zero bit.

Thanks to those who attempted to solve this question.

like image 76
Rob Olmos Avatar answered Sep 28 '22 01:09

Rob Olmos