【发布时间】: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