Is there any way to get frame by frame using AVCaptureSession object in swift?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 07:24:53

问题


I have to process frames which are captured by iPhone camera using my c++ functions. So I use startRunning() function to start the flow of data, but in what way I can process each frame?


回答1:


Yes, it is pretty straight forward. You need to

  1. Create an AVCaptureVideoDataOutput object to produce video frames
  2. Implement a delegate for the AVCaptureVideoDataOutput object to process video frames
  3. In the delegate class, implement the method (captureOutput:didOutputSampleBuffer:fromConnection:) that is called when a sample buffer is written.

For more information you can read this part of the AVFoundation Programming Guide. The code samples are in Objective-C not swift but i think you get the idea.




回答2:


I created a class that may help you out: CameraCaptureHelper wraps up all the AVFoundation stuff and invokes a method on its delegate where it passes a CIImage with each frame.



来源:https://stackoverflow.com/questions/35255580/is-there-any-way-to-get-frame-by-frame-using-avcapturesession-object-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!