I'm trying to take 5 pictures every second with AVCaptureSession and I'm not sure I understand what AVFrameRange means. Currently I have some code that sets up the device:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
and tries to set the activeVideoMinFrameDuration
and activeVideoMaxFrameDuration
to a custom value of CMTimeMake(1, 5)
. Apple tells me I can only use one of the AVFrameRanges that they've provided.
When I NSLogged them, I get (2, 30), (2,60), and (2,24). I first want to know what this means? Is this the frame rate at which the camera will run or an interval for capturing frames (i.e. what I'm trying to do)?
If it isn't, what can I do to save 5 frames every second on my sampleBufferDelegate method? Currently it gives me every single frame because the method is called every single time there is a frame, so I just need some pointer on how I can grab just 5 at each second.
Here is working code we have used that sets the frame rate at 5 per second.
If you measure calls to CaptureOutput while using this code, you can see that the camera frames are called every 200 msecs (i.e. which is 5 frames per second.) (We just tested this to confirm.)
Change desiredFrameRate to get other camera frame rates.
Code for choosing custom frame rate is as below - Added checks to Apple RosyWriter to verify if current format supports FPS chosen
In case current format (
activeFormat
) didn't support your chosen FPS, use below code to changeactiveFormat
and then chose FPS. Will need to get format dimension to match your needs though.Note: Usage of
AVCaptureConnection
videoMinFrameDuration
to set FPS is deprecated.