iOS AVCaptureSession - 如何获取/设置每秒记录的帧数?

时间:2012-12-26 10:27:26

标签: ios frame-rate avcapturesession

我是AVCaptureSession的新手,希望更好地了解如何使用它。 因此,我将视频流捕获为分离的CIImages并将其转换为UIImages。 现在我希望能够获得每秒帧数的数量,并且最好能够设置它。

知道怎么做吗?

4 个答案:

答案 0 :(得分:14)

AVCaptureConnection's videoMinFrameDuration已被弃用。

您可以使用AVCaptureDevice属性检测支持的视频帧速率范围,并可以使用属性分配最小和最大帧速率。

device.activeFormat.videoSupportedFrameRateRanges返回设备支持的所有视频帧速率范围。

device.activeVideoMinFrameDurationdevice.activeVideoMaxFrameDuration可用于指定帧持续时间。

答案 1 :(得分:9)

您可以使用AVCaptureConnection的{​​{1}}访问者来设置值。

请参阅AVCaptureConnection documentation

考虑videoMinFrameDurationoutput对象。

AVCaptureVideoDataOutput

更多信息,请参阅此SO question

中的答案

答案 2 :(得分:1)

要设置捕获会话的帧速率,必须使用 device.activeVideoMinFrameDuration device.activeVideoMaxFrameDuration 在设备上进行设置(如有必要)。

Swift 4 中,您可以执行以下操作:

extension AVCaptureDevice {
    func set(frameRate: Double) {
    guard let range = activeFormat.videoSupportedFrameRateRanges.first,
        range.minFrameRate...range.maxFrameRate ~= frameRate
        else {
            print("Requested FPS is not supported by the device's activeFormat !")
            return
    }

    do { try lockForConfiguration()
        activeVideoMinFrameDuration = CMTimeMake(value: 1, timescale: Int32(frameRate))
        activeVideoMaxFrameDuration = CMTimeMake(value: 1, timescale: Int32(frameRate))
        unlockForConfiguration()
    } catch {
        print("LockForConfiguration failed with error: \(error.localizedDescription)")
    }
  }
}

并命名为

device.set(frameRate: 60)

答案 3 :(得分:0)

这样做

if let frameSupportRange = currentCamera.activeFormat.videoSupportedFrameRateRanges.first {
    captureSession.beginConfiguration()
    // currentCamera.activeVideoMinFrameDuration = CMTimeMake(1, Int32(frameSupportRange.maxFrameRate))
    currentCamera.activeVideoMinFrameDuration = CMTimeMake(1, YOUR_FPS_RATE)
    captureSession.commitConfiguration()
}
相关问题