How to decode a H.264 frame on iOS by hardware decoding?

后端 未结 2 439
遇见更好的自我
遇见更好的自我 2021-02-02 16:28

I have been used ffmpeg to decode every single frame that I received from my ip cam. The brief code looks like this:

-(void) decodeFrame:(unsigned char *)frameDa         


        
2条回答
  •  野的像风
    2021-02-02 16:44

    iOS does not provide any public access directly to the hardware decode engine, because hardware is always used to decode H.264 video on iOS.

    Therefore, session 513 gives you all the information you need to allow frame-by-frame decoding on iOS. In short, per that session:

    • Generate individual network abstraction layer units (NALUs) from your H.264 elementary stream. There is much information on how this is done online. VCL NALUs (IDR and non-IDR) contain your video data and are to be fed into the decoder.
    • Re-package those NALUs according to the "AVCC" format, removing NALU start codes and replacing them with a 4-byte NALU length header.
    • Create a CMVideoFormatDescriptionRef from your SPS and PPS NALUs via CMVideoFormatDescriptionCreateFromH264ParameterSets()
    • Package NALU frames as CMSampleBuffers per session 513.
    • Create a VTDecompressionSessionRef, and feed VTDecompressionSessionDecodeFrame() with the sample buffers
      • Alternatively, use AVSampleBufferDisplayLayer, whose -enqueueSampleBuffer: method obviates the need to create your own decoder.

提交回复
热议问题