gpt4 book ai didi

swift - 将 AVCaptureDevice 设置为 1 fps 时出现相机问题

转载 作者:行者123 更新时间:2023-11-28 07:51:31 25 4
gpt4 key购买 nike

我对 AVFoundation 框架有疑问。每当我将相机的 FPS 设置为 1 时,一段时间后,我的 FaceTime HD 相机 LED 开始以一秒的间隔闪烁。此外,不再调用对委托(delegate)(示例缓冲区委托(delegate))的调用。

当我将其设置为 2 FPS 时不会出现此问题,但对于我正在开发的应用程序,我需要将其设置为 1 FPS。

如果其他人在将相机设置为 1 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()
}

最佳答案

如何处理帧?如果您使用 AVCaptureVideoDataOutput 进行此操作,您可以丢弃任何您不想达到所需帧率的帧。如果您正在录制到文件(例如 AVCaptureMovieFileOutput),则不能。

p.s 你描述的问题听起来像是一个错误。理想情况下,您会记录它。

关于swift - 将 AVCaptureDevice 设置为 1 fps 时出现相机问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49522934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com