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

iOS AVCaptureSession-如何获取/设置每秒录制的帧数?,ios,frame-rate,avcapturesession,Ios,Frame Rate,Avcapturesession,我是AVCaptureSession的新手,希望更好地了解如何使用它。 因此,我设法将视频流捕获为单独的图像,并将其转换为UIImage。 现在我希望能够获得每秒捕获的帧数,最好能够设置它 你知道怎么做吗?你可以使用AVCaptureConnection的videoMinFrameDuration访问器来设置值 见 考虑outputbeAVCaptureVideoDataOutput对象 AVCaptureConnection *conn = [output connectionWithMedi

我是AVCaptureSession的新手,希望更好地了解如何使用它。 因此,我设法将视频流捕获为单独的图像,并将其转换为UIImage。 现在我希望能够获得每秒捕获的帧数,最好能够设置它


你知道怎么做吗?

你可以使用
AVCaptureConnection
videoMinFrameDuration
访问器来设置值

考虑
output
be
AVCaptureVideoDataOutput
对象

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);

有关详细信息,请参见本节中的我的答案。AVCaptureConnection的videoMinFrameDuration已被弃用

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

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

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

这样做

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()
}

要设置捕获会话帧速率,必须使用设备.activeVideoMinFrameDuration设备.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)

我的fps是否保证不会低于我的最小/最大值?我如何才能得到我当前的实际fps,而不是最小值和最大值?@Tylerpfafaff你找到你的问题的答案了吗?@Crashalot太长了,我不记得了:(这些属性现在已被弃用。是否有其他方法?@ShravyaBoggarapu检查我下面的答案。我已经更新了它。