【问题标题】:AVCaptureDevice Unsupported frame duration iPhone 11 Pro MaxAVCaptureDevice 不支持的帧持续时间 iPhone 11 Pro Max
【发布时间】:2019-11-27 06:11:00
【问题描述】:

我在新的 iPhone 11 之前一直使用 AVCaptureDevice 方法集 activeVideoMinFrameDuration 没有任何问题,但是使用新的 iPhone 11 Pro max 测试相同的代码(实际设备),应用程序崩溃并显示错误消息:-

由于未捕获的异常“NSInvalidArgumentException”而终止应用,原因:-[AVCaptureDevice setActiveVideoMinFrameDuration:] 不支持的帧持续时间 - 使用 -activeFormat.videoSupportedFrameRateRanges 发现有效范围

相同的代码适用于旧手机。实际上我使用的是来自Apple documentation的确切示例代码

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

正如我上面提到的,此代码适用于较旧的设备,但不适用于 iPhone 11 系列(在 11 Pro max 上测试)。

是否有人对此问题有解决方法或解决方案?

【问题讨论】:

  • 您是否正在解决一些首选视频稳定模式?
  • @BandishDave 当时我正在开发直播应用程序,我能够按照接受的答案中的描述解决问题。

标签: ios objective-c swift iphone


【解决方案1】:

适用于将来遇到同样问题的任何人。这是我通过遵循调试错误描述来解决问题的方法。

 // Important part: You must get the supported frame duration and use it to set max and min frame durations. 
let supporrtedFrameRanges = device.activeFormat.videoSupportedFrameRateRanges.first

// Then use it, note that only fall back to bestFrameRateRange if supporrtedFrameRanges is nil.            
device.activeVideoMinFrameDuration = supporrtedFrameRanges?.minFrameDuration ?? bestFrameRateRange.minFrameDuration
device.activeVideoMaxFrameDuration = supporrtedFrameRanges?.maxFrameDuration ?? bestFrameRateRange.maxFrameDuration

【讨论】:

  • 我被困在视频稳定之前或之后的视频录制任务中......如果可以的话,你能帮我吗?
  • 嗨,@BandishDave 我认为你必须就你的问题发布一个全新的问题,这样你就可以得到更多人的帮助。请务必发布详细信息,包括您对问题的尝试。
猜你喜欢
  • 2020-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-17
  • 1970-01-01
相关资源
最近更新 更多