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

问题描述 投票:12回答:4

我是新来AVCaptureSession并希望更好地了解如何使用它。所以我设法捕获视频流作为分离CIImages并将其转换为UIImages。现在,我希望能够获得第二捕捉每秒帧数的数量,最好是能设置。

任何想法如何做到这一点?

ios frame-rate avcapturesession
4个回答
9
投票

你可以使用AVCaptureConnectionvideoMinFrameDuration访问设定值。

AVCaptureConnection documentation

考虑outputAVCaptureVideoDataOutput对象。

AVCaptureConnection *conn = [output connectionWithMediaType:AVMediaTypeVideo];

if (conn.isVideoMinFrameDurationSupported)
    conn.videoMinFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);
if (conn.isVideoMaxFrameDurationSupported)
    conn.videoMaxFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);

更多信息,请参阅我的答案在此SO question


14
投票

AVCaptureConnection's videoMinFrameDuration已被弃用。

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

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

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


1
投票

要设置捕获会话帧速率,您必须将其设置使用device.activeVideoMinFrameDuration和device.activeVideoMaxFrameDuration(如有必要)的设备上。

在斯威夫特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)

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()
}
© www.soinside.com 2019 - 2024. All rights reserved.