How can we get H.264 encoded video stream from iPhone Camera?

后端 未结 2 1692
梦如初夏
梦如初夏 2021-02-06 10:03

I am using following to get video sample buffer:

- (void) writeSampleBufferStream:(CMSampleBufferRef)sampleBuffer ofType:(NSString *)mediaType

2条回答
  •  抹茶落季
    2021-02-06 10:16

    Update for 2017:

    You can do streaming Video and Audio now by using the VideoToolbox API. Read the documentation here: VTCompressionSession

    Original answer (from 2013):

    Short: You can't, the sample buffer you receive is uncompressed.

    Methods to get hardware accelerated h264 compression:

    • AVAssetWriter
    • AVCaptureMovieFileOutput

    As you can see both write to a file, writing to a pipe does not work as the encoder updates header information after a frame or GOP has been fully written. So you better don't touch the file while the encoder writes to it as it does randomly rewrite header information. Without this header information the video file will not be playable (it updates the size field, so the first header written says the file is 0 bytes). Directly writing to a memory area is not supported currently. But you can open the encoded video-file and demux the stream to get to the h264 data (after the encoder has closed the file of course)

提交回复
热议问题