3

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 次 1 秒

PS:设备版本为iPhone 5C和iOS 8.12

4

2 回答 2

16

我刚遇到同样的问题。你应该看看关于setActiveVideoMinFrameDuration或setActiveVideoMaxFrameDuration的函数解释。苹果 说:

在 iOS 上,接收器的 activeVideoMinFrameDuration 在以下条件下重置为其默认值:
- 接收器的 activeFormat 更改
- 接收器的 AVCaptureDeviceInput 会话的 sessionPreset 更改
- 接收器的 AVCaptureDeviceInput 被添加到会话

因此,您应该在更改 activeFormat、sessionPreset 和 AVCaptureSession 的 addInput​​调用 setActiveVideoMinFrameDuration 和 setActiveVideoMaxFrameDuration 。

于 2015-06-05T07:01:21.157 回答
0

迅速

对于那些正在寻找优雅的 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.
     }
 }
}

参考: 苹果官方文档

于 2019-11-14T06:50:51.170 回答