Search code examples
iosswiftavfoundationavcapturesession

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?


Solution

  • 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.