Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 509
albertpod Avatar asked Feb 07 '16 15:02

albertpod


2 Answers

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.

like image 124
Wael Showair Avatar answered Nov 08 '22 07:11

Wael Showair


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.

like image 23
Simon Gladman Avatar answered Nov 08 '22 08:11

Simon Gladman