I managed to get video playback working in VLC but not QuickTime. I used code similar to what I posted above to get H.264 NALs into CMSampleBuffers.
I had two main issues:
- I was not setting CMSampleTimingInfo correctly (as my comment above states).
- I was not packing the raw NAL data correctly (not sure where this is documented, if anywhere).
To solve #1, I set timing.duration = CMTimeMake(1, fps);
where fps is the expected frame rate. I then set timing.decodeTimeStamp = kCMTimeInvalid;
to mean that the samples will be given in decoding order. Lastly, I set timing.presentationTimeStamp
by calculating the absolute time, which I also used with startSessionAtSourceTime
.
To solve #2, through trial and error I found that giving my NAL units in the following form worked:
[7 8 5] [1] [1] [1]..... [7 8 5] [1] [1] [1]..... (repeating)
Where each NAL unit is prefixed by a 32-bit start code equaling 0x00000001
.
Presumably for the same reason it's not playing in QuickTime, I'm still having trouble moving the resulting .mov file to the photo album (the ALAssetLibrary
method videoAtPathIsCompatibleWithSavedPhotosAlbum
is failing stating that the "Movie could not be played." Hopefully someone with an idea about what's going on can comment. Thanks!