我们如何从iPhone Camera获得H.264编码的视频流? [英] How can we get H.264 encoded video stream from iPhone Camera?

查看:525
本文介绍了我们如何从iPhone Camera获得H.264编码的视频流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下来获取视频样本缓冲区:

I am using following to get video sample buffer:

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

现在我的问题是如何从上面获取h.264编码的NSData <强> sampleBuffer 即可。请建议。

Now my question is that how can I get h.264 encoded NSData from above sampleBuffer. Please suggest.

推荐答案

2017年更新:

您现在可以使用 VideoToolbox API来播放视频和音频。
请阅读此处的文档: VTCompressionSession

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

原始答案(自2013年起):

短:您不能,您收到的样本缓冲区未压缩。

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

获得硬件加速h264压缩的方法:

Methods to get hardware accelerated h264 compression:

  • AVAssetWriter
  • AVCaptureMovieFileOutput

正如你可以看到写入文件一样,写入管道不起作用,因为编码器在帧后更新标题信息或者GOP已经写完了。因此,当编码器写入文件时,最好不要触摸文件,因为它会随机重写标题信息。如果没有此标头信息,视频文件将无法播放(它会更新大小字段,因此写入的第一个标头表示文件为0字节)。目前不支持直接写入存储区。但您可以打开编码的视频文件并对流进行解复用以获取h264数据( 编码器当然关闭文件后)

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)

这篇关于我们如何从iPhone Camera获得H.264编码的视频流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆