I have the h264 stream inAnnex B format and follow this link here to implements h264 decoding with iOS8 videoToolBox.
I check the OSStatus in every step.
use CMVideoFormatDescriptionCreateFromH264ParameterSets with the SPS and PPS data to create a CMFormatDescription.(status == noErr)
create a VTDecompressionSession using VTDecompressionSessionCreate. (status == noErr)
capture the NALUnit payload into a CMBlockBuffer making sure to replace the start code with
a byte length code. (status == noErr)
create a CMSampleBuffer. (status == noErr)
use VTDecompressionSessionDecodeFrame and get error code -8969(simulator), -12909(device) in callback function.
I doubt I did something wrong in step3, I am not pretty sure what the length code means. I just follow the WWDC session video replace every NALUnit start code 00 00 00 01 to 00 00 80 00. Is it right or not ? or I should check something else ?? thanks
Finally, got it working now. So, I share the details on how to use the VideoToolbox to decode h.264 stream data:
CMFormatDescription
by using CMVideoFormatDescriptionCreateFromH264ParameterSets
.VTDecompressionSession
by using VTDecompressionSessionCreate
.CMBlockBuffer
.CMSampleBuffer
by using CMSampleBufferCreate
.VTDecompressionSessionDecodeFrame
and get the result from callback.then, you have to use dispatch_semaphore_t to control frame decoding and showing. I upload the sample project on my git. hope to help someone else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With