I am learning about AVCaptureSession and how to capture multiple images with its delegate method
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
My goal is to capture 1 or many images with a predefined rate per second. For example, 1 or 2 images per 1 second. So I set
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
captureOutput.alwaysDiscardsLateVideoFrames = YES;
captureOutput.minFrameDuration = CMTimeMake(1, 1);
When [self.captureSession startRunning];
is started my log file shows delegate is being called 20 times a second. Where is it coming from and how to capture images with my intended intervals?
You can use the function given below and if you want to capture at specific intervals, then set a timer and call that function again.
For more reference you can see iOS4: Take photos with live video preview using AVFoundation.
Something that I struggled with for a while was a massive delay (~5 sec) when taking a picture, and trying to set a UIImage with the captured image. in the
method, you cant use normal functions such as
[self.image setImage:img]
for things that are linked to the UI, you have to run them on the main thread like so:Hope this helps someone