h.264video-encodingms-media-foundationsmooth-streaming

SPS and PPS (aka dwSequenceHeader) in Media Foundation's H264 encoder


I'm using the H264 encoder from Media Foundation (MFT).
I extracted the SPS and PPS from it, because I need it for smooth streaming.
The MSDN says that the number of bytes used for the length field that appears before each NALU can be 1, 2, or 4. This is all in network byte order. As you can see, the first 4 bytes in the buffer are 0, 0, 0, 1. If we apply any of the possible lengths, we will get nothing. If the number of bytes used for length is 1, then the length is zero, if it is 2, the length is zero again. If it is 4, the length of first NALU is 1?! And, that's not correct.
Does anybody know how should I interpret this SPS and PPS concatenated together??

extracted SPS + PPS


Solution

  • The answer here is simple: the data is valid and formatted according to Annex B, prefixed by start codes 00 00 00 01 and not run length encoding.

    H.264 extradata (partially) explained - for dummies

    Annex B format

    in this format, each NAL is preceeded by a four byte start code: 0x00 0x00 0x00 0x01 thus in order to know where a NAL start and where it stops, you would need to read each byte of the bitstream, looking for these start codes, which can be a pain if you need to convert between this format and the other format.

    More details on H.264 spec - freely available for download. Page 326 starts with "Annex B - Byte stream format".