【问题标题】:AVFoundation I use setActiveVideoMinFrameDuration didn't work我使用 setActiveVideoMinFrameDuration 的 AVFoundation 不起作用
【发布时间】:2015-04-28 04:33:51
【问题描述】:

我在演示中使用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

【问题讨论】:

  • 让它成为 CMTimeMake(1, 10) 然后检查发生了什么..?
  • 没有改变,信息每秒打印 24 次
  • 您使用的是哪些设置?你确定 1FPS 是一个兼容的选项吗?
  • 你在打电话给 [device unlockForConfiguration];最后?
  • 是的,我调用了 [device unlockForConfiguration];并在我修改之前锁定

标签: ios avfoundation avcapture


【解决方案1】:

我也遇到了同样的问题,你应该看看setActiveVideoMinFrameDuration或setActiveVideoMaxFrameDuration的函数说明。 苹果说:

在 iOS 上,接收器的 activeVideoMinFrameDuration 在以下情况下会重置为其默认值:
- 接收方的 activeFormat 改变
- 接收者的 AVCaptureDeviceInput 的 session 的 sessionPreset 改变
- 接收者的 AVCaptureDeviceInput 被添加到会话中

所以,你应该在 改变 activeFormat、sessionPreset 和 AVCaptureSession 的 addInput 之后调用 setActiveVideoMinFrameDuration 和 setActiveVideoMaxFrameDuration。

【讨论】:

  • 还有一件事让你对 Apple 的文档感到抓狂......为什么在函数头中提到了如此重要的条件而不是在官方文档中?!?!?!苹果的两面……一个永无止境的故事……
【解决方案2】:

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.
     }
 }
}

参考: Apple Official Documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    相关资源
    最近更新 更多