For others encountering this issue, the more generic way to solve this problem is to choose the format that satisfies your desired conditions.
For example, if you wanted to choose a format in 720p and compatible with 60 fps, you could do the following:
let frameDuration = CMTimeMake(value: 1, timescale: 60)
// Get format that is 720p resolution and is compatible with 60 fps.
let format = device.formats.first {
let dimensions = $0.formatDescription.dimensions
let hasCompatibleFrameRateRange = $0.videoSupportedFrameRateRanges.contains {
$0.minFrameRate <= 60 && 60 <= $0.maxFrameRate
}
return dimensions.width == 1280 && dimensions.height == 720 && hasCompatibleFrameRateRange
}
if let format = format {
device.activeFormat = format
device.activeVideoMinFrameDuration = frameDuration
device.activeVideoMaxFrameDuration = frameDuration
}
Topic:
App & System Services
SubTopic:
Hardware
Tags: