title: How to inspect H264/AVC ISO/IEC 14496-15 AVCDecoderConfigurationRecord?
body: <p>Some historic background: I'm currently working with Wowza and attempting to decode the <em>AMFPackets</em> that come from the <em>IMediaStream</em>. The video packets will have a 5-byte header and the first packet is the codec configuration.</p>
  
  <p>So far in my inspecting the codec configuration matches the <strong>ISO/IEC 14496-15 AVCDecoderConfigurationRecord</strong> layout. However, I'm having trouble decoding the <strong>SPS</strong> and <strong>PPS</strong> units.</p>
  
  <h2>The codec config packet including the 5-byte header:</h2>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <h2>Flash/Wowza-specific first is the header:</h2>
  
  <blockquote>
    <p>17 00 00 00 00</p>
  </blockquote>
  
  <ul>
  <li>17 = 10111 = H.264 K frame</li>
  <li>00 = 0 = codec config packet</li>
  <li>000000 = 0 = start time 0</li>
  </ul>
  
  <h2>Next is the AVCDecoderConfigurationRecord (hex = decimal):</h2>
  
  <ul>
  <li>configurationVersion: 01 = 1</li>
  <li>AVCProfileIndication: 4D = 77 (Main)</li>
  <li>profile_compatibility: 00 = 0 </li>
  <li>AVCLevelIndication: 15 = 21 (2.1)</li>
  <li>6 bits reserved + lengthSizeMinusOne:  03 = 00000011 = 3 (4 bytes)</li>
  <li>3 bits reserved + numOfSequenceParameterSets:  01 = 0001 = 1</li>
  <li>sequenceParameterSetLength: 002F = (47 bytes)</li>
  <li>(SPS record 47 bytes long)</li>
  <li>numOfPictureParameterSets: 01 = 1</li>
  <li>pictureParameterSetLength: 0004 = (4 bytes)</li>
  <li>(PPS record 4 bytes long)</li>
  <li>(end)</li>
  </ul>
  
  <h2>SPS record (47 bytes):</h2>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>Assuming this is a NAL unit containing SPS type:
  (Using <strong>ITU-T H.264 06/2011 7.3.1 NAL unit syntax</strong>)</p>
  
  <ul>
  <li>First byte: 67 = 1100111</li>
  <li>forbidden_zero_bit: 1 (Oops, forbidden 0 bit set to 1?)</li>
  <li>nal_ref_idc: 2</li>
  <li>nal_unit_type: 0111 = 7 (SPS)</li>
  </ul>
  
  <p>Assuming the SPS payload follow:
  (Using <strong>ITU-T H.264 06/2011 7.3.2.1.1 Sequence parameter set data syntax</strong>)</p>
  
  <ul>
  <li>profile_idc: 4D = 77 (Main, matches)</li>
  <li>constraints + 2 bits reserved (equal to 0): 40 = 1000000 (Looks fine)</li>
  <li>level_idc: 15 (2.1, matches)</li>
  </ul>
  
  <p>Assuming this is only a SPS:
  (Using <strong>ITU-T H.264 06/2011 7.3.2.1.1 Sequence parameter set data syntax</strong>)</p>
  
  <ul>
  <li>profile_idc: 67 = 103 (I think this should be 77 like AVCProfileIndication?)</li>
  <li>constraints + 2 bits reserved (equal to 0): 4D = 1001101 (Uh oh, reserved bit set?)</li>
  <li>level_idc: 77 (Shouldn't this be 21 like AVCLevelIndication?)</li>
  </ul>
  
  <p><strong>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?</strong></p>
  
  <p>Thanks</p>