iosavfoundationavcapture

AVFoundation I use setActiveVideoMinFrameDuration didn't work


I use AVCaptureVideoDataOutput in my demo ,for take photos in loop (like scanner) without sound, so i set fps to low Level

[device setActiveVideoMinFrameDuration:CMTimeMake(1, 1)];
[device setActiveVideoMaxFrameDuration:CMTimeMake(1, 1)];

In my code, then do this

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
   fromConnection:(AVCaptureConnection *)connection
{
     NSLog(@"date");
}

for check is it work, I found it print 24 times in a second,not 1 times 1 second

PS: the device edition is iPhone 5C and iOS 8.12


Solution

  • I just met the same problem.You should take a look at the function explanation about setActiveVideoMinFrameDuration or setActiveVideoMaxFrameDuration. Apple says:

    On iOS, the receiver's activeVideoMinFrameDuration resets to its default value under the following conditions:
    - The receiver's activeFormat changes
    - The receiver's AVCaptureDeviceInput's session's sessionPreset changes
    - The receiver's AVCaptureDeviceInput is added to a session

    So, you should call setActiveVideoMinFrameDuration and setActiveVideoMaxFrameDuration after changing activeFormat,sessionPreset and AVCaptureSession's addInput.