8

I've tried creating CMVideoFormatDescriptionRef with CMVideoFormatDescriptionCreateFromH264ParameterSets but it fails with -12712 error (which does not seem to be defined in any header)

I've taken my SPS and PPS from an avcC atom of a mov file (created by an iPhone camera app):

61 76 63 43 01 64 00 29 FF E1 00 10 67 64 00 29 AC 56 80 78 02 27 E5 9A 80
80 80 81 01 00 05 28 EE 04 F2 C0

SPS seems to be: 67 64 00 29 AC 56 80 78 02 27 E5 9A 80 80 80 81

...and the PPS: 28 EE 04 F2 C0

I've preceeded SPS and PPS with their 4-byte lengths (tried also 1-byte and 2-byte lenghts with the same results) and issued the call like that:

uint8_t sps[] = {0x00, 0x00, 0x00, 0x10, 0x67, 0x64, 0x00, 0x29, 0xAC, 0x56, 0x80, 0x78, 0x02, 0x27, 0xE5, 0x9A, 0x80, 0x80, 0x80, 0x81};

uint8_t pps[] = {0x00, 0x00, 0x00, 0x05, 0x28, 0xEE, 0x04, 0xF2, 0xC0};

uint8_t* props[] = {sps, pps};

size_t sizes[] = {0x14, 0x09}; // sizes include the 4-byte length

CMVideoFormatDescriptionRef formatDesc;

OSStatus formatCreateResult = CMVideoFormatDescriptionCreateFromH264ParameterSets(NULL, 2, props, sizes, 4, &formatDesc);

I get -12712 as the result every single time (tried SPS / PPS from several files and streams).

Do you have any idea what do I do wrong ? (The code was checked on Xcode6-Beta4 on Simulator). I'd prefer to avoid parsing SPS and PPS on my own and using plain CMVideoFormatDescriptionCreate :-)

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
ZukGnojak
  • 83
  • 1
  • 3
  • Can you explain to me how you find the SPS and the PPS? I am having trouble getting all the parameters for CMVideoFormatDescriptionCreateFromH264ParameterSets() from an H.264 elementary stream. – Joride Oct 26 '14 at 18:38
  • 2
    @Joride SPS is NALU type 7 and PPS is NALU 8. You can find the type as the last 5 bits of the first byte of the NALU (after the start code in the case of elementary). – braden Nov 28 '14 at 20:33
  • Thanks Braden, that 'last 5 bits' part was unclear to me. Now I see how I can get the type. Thanks! – Joride Nov 29 '14 at 08:17
  • I'm trying to get off of using a software codec, so I'm working on parsing the stream. I was under the impression that the NALU type for SPS is 0x67 and for PPS it's 0x68. This seems to be the case in when dumping an elementary H264 byte stream. Should I not be expecting this? – Joey Carson Jan 04 '16 at 15:04
  • Ah, I came across this post https://cardinalpeak.com/blog/the-h-264-sequence-parameter-set/ and it looks like I should just be masking out the 3 most significant bits in the first byte and comparing. Some older explanations I came across suggested I should be looking for 0x67, and it was hard to argue because this is how the byte stream I was inspecting always looked. – Joey Carson Jan 04 '16 at 15:14

2 Answers2

13

Do not include the 4 byte size. Either in the sps/pps payloads, nor the size values.

szatmary
  • 29,969
  • 8
  • 44
  • 57
  • That did it man, thanks. Apparently the NAL header length param is for the NAL units to be decoded with the decompression session only, not for the SPS and PPS passed here :-) – ZukGnojak Aug 02 '14 at 10:04
-4

I googled for you ;-)

Check this Chromium code

https://src.chromium.org/svn/trunk/src/content/common/gpu/media/vt_video_decode_accelerator.cc

And this answer about H.264 SPS/PPS NALU

Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream

Community
  • 1
  • 1
9dan
  • 4,222
  • 2
  • 29
  • 44