【发布时间】:2018-03-27 21:46:38
【问题描述】:
我对 AVFoundation 框架有疑问。每当我将相机的 FPS 设置为 1 时,一段时间后,我的 FaceTime 高清相机 LED 开始以一秒的间隔闪烁。此外,不再调用委托(样本缓冲区委托)。
当我将其设置为 2 FPS 时不会出现此问题,但对于我正在开发的应用程序,我需要将其设置为 1 FPS。
只需在此处检查是否有人在将相机设置为 FPS 时遇到问题。如有必要,我将向 Apple 发布错误报告。 我从 2013 年中期开始使用 Macbook Air,运行 macOS 10.13.3。
这是我用来设置 FPS 的代码:
/// Set the frame rate of the current av capture session, if it is supported by the camera.
///
/// - Parameter fps: The desired frames per second.
func set(fps: Int) {
guard let captureDevice = captureDevice,
let format = captureDevice.activeFormat else { return }
let doubleFPS = Double(fps)
// Lock the device before changing the frame rate.
try? captureDevice.lockForConfiguration()
// Look for a supported frame rate range that is supported by the camera.
for range in format.videoSupportedFrameRateRanges as! [AVFrameRateRange] {
if range.minFrameRate <= doubleFPS &&
range.maxFrameRate >= doubleFPS {
let time: CMTime = CMTime(value: 1, timescale: CMTimeScale(fps))
captureDevice.activeVideoMaxFrameDuration = time
captureDevice.activeVideoMinFrameDuration = time
break
}
}
// Unlock the device now that we are done.
captureDevice.unlockForConfiguration()
}
【问题讨论】:
标签: swift macos avfoundation avcapturesession