我在我的演示中使用AVCaptureVideoDataOutput
来拍摄没有声音的循环照片(如扫描仪),
所以我将fps设置为低级别
[device setActiveVideoMinFrameDuration:CMTimeMake(1, 1)];
[device setActiveVideoMaxFrameDuration:CMTimeMake(1, 1)];
在我的代码中,然后执行此操作
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
NSLog(@"date");
}
检查是否有效,我发现它每秒打印24次,而不是1次打印
PS:设备版本是iPhone 5C和iOS 8.12
答案 0 :(得分:10)
我刚遇到同样的问题。您应该查看有关setActiveVideoMinFrameDuration或setActiveVideoMaxFrameDuration的函数说明。 Apple说:
在iOS上,接收者的activeVideoMinFrameDuration在以下条件下重置为默认值:
- 接收者的activeFormat更改
- 接收者的AVCaptureDeviceInput会话的sessionPreset更改
- 接收者的AVCaptureDeviceInput被添加到会话
因此,您应该在更改activeFormat,sessionPreset和AVCaptureSession的addInput之后调用setActiveVideoMinFrameDuration和setActiveVideoMaxFrameDuration 。
答案 1 :(得分:0)
SWIFT
对于那些正在寻找优雅的Swifty解决方案的人来说,这是我从最新的官方文档中获得的信息
以下代码示例说明了如何选择iOS设备的最高可能帧频:
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.
}
}
}