如何在录制视频时以编程方式拍摄照片
iPhone 5S能够在录制视频时拍照,我正在试图弄清楚如何以编程方式执行此操作。我知道我会使用AVFoundation,但是,我在编程指南。我还检查了示例项目(与AVFoundation相关)并且看起来没有任何东西能够满足我的需求。如果你可以帮我指出一个很好的方向。
The iPhone 5S is capable of taking pictures while recording video and I am trying to figure out how I would do this programatically. I know I would be utilizing AVFoundation, however, I couldn't find anything in the programming guide regarding this. I have also checked the sample projects (AVFoundation-related) and it doesn't look like there is anything there that does what I am looking for. if you could help point me in the right direction that would be great.
实际上你可以用任何能够录制视频:
Actually you can do it with any device that can record video:
- 创建并配置
AVCaptureVideoDataOutput
。 - 将其添加到您的
AVCaptureSession
。 - 添加
AVCaptureVideoDataOutputSampleBufferDelegate
。 - 在委托中实现
captureOutput:didOutputSampleBuffer:fromConnection:
并使用imageFromSampleBuffer获取图像:
。
- Create and configure a
AVCaptureVideoDataOutput
. - Add it to your
AVCaptureSession
. - Add a
AVCaptureVideoDataOutputSampleBufferDelegate
. - Implement
captureOutput:didOutputSampleBuffer:fromConnection:
in the delegate and get the image withimageFromSampleBuffer:
.
可以找到一些类似的代码这里,其中以给定间隔捕获图像,但您只需要一个图像。
Some similar code can be found here, where images are captured at a given interval, but you only want one image.