【发布时间】:2012-12-26 10:27:26
【问题描述】:
我是 AVCaptureSession 的新手,希望更好地了解如何使用它。 所以我设法将视频流捕获为单独的 CIImages 并将它们转换为 UIImages。 现在我希望能够获取每秒捕获的帧数,并且最好能够设置它。
知道怎么做吗?
【问题讨论】:
标签: ios frame-rate avcapturesession
我是 AVCaptureSession 的新手,希望更好地了解如何使用它。 所以我设法将视频流捕获为单独的 CIImages 并将它们转换为 UIImages。 现在我希望能够获取每秒捕获的帧数,并且最好能够设置它。
知道怎么做吗?
【问题讨论】:
标签: ios frame-rate avcapturesession
AVCaptureConnection's videoMinFrameDuration 已弃用。
您可以使用AVCaptureDevice 属性来检测支持的视频帧速率范围,并可以使用属性分配最小和最大帧速率。
device.activeFormat.videoSupportedFrameRateRanges 返回设备支持的所有视频帧率范围。
device.activeVideoMinFrameDuration 和 device.activeVideoMaxFrameDuration 可用于指定帧持续时间。
【讨论】:
您可以使用AVCaptureConnection 的videoMinFrameDuration 访问器来设置值。
见AVCaptureConnection documentation
将output 视为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);
更多信息,请在SO question查看我的回答
【讨论】:
要设置捕获会话帧速率,您必须使用 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)
【讨论】:
这样做
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()
}
【讨论】: