Reputation: 188
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
Upvotes: 5
Views: 2753
Reputation: 4452
SWIFT
For those who are looking for an elegant Swifty solution, here is what I got from the latest official documentation
The following code example illustrates how to select an iOS device’s highest possible frame rate:
func configureCameraForHighestFrameRate(device: AVCaptureDevice) {
var bestFormat: AVCaptureDevice.Format?
var bestFrameRateRange: AVFrameRateRange?
for format in device.formats {
for range in format.videoSupportedFrameRateRanges {
if range.maxFrameRate > bestFrameRateRange?.maxFrameRate ?? 0 {
bestFormat = format
bestFrameRateRange = range
}
}
}
if let bestFormat = bestFormat,
let bestFrameRateRange = bestFrameRateRange {
do {
try device.lockForConfiguration()
// Set the device's active format.
device.activeFormat = bestFormat
// Set the device's min/max frame duration.
let duration = bestFrameRateRange.minFrameDuration
device.activeVideoMinFrameDuration = duration
device.activeVideoMaxFrameDuration = duration
device.unlockForConfiguration()
} catch {
// Handle error.
}
}
}
Reference: Apple Official Documentation
Upvotes: 0
Reputation: 326
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.
Upvotes: 21