目前我有一个带AVCaptureVideoDataOutput的AVCaptureSession。我的理解是每次摄像机捕获帧时都会调用captureOutput委托函数。默认情况下,表示captureOutput函数以30fps调用。
我还有一个CMMotionManager在手机移动时存储数据。运动管理器以大约90-100fps的速度运行。
无论如何我可以增加相机拍摄帧数的fps,以便以与motionManager大致相同的速度调用captureOutput函数吗?
任何帮助都将不胜感激。
答案 0 :(得分:1)
答案 1 :(得分:0)
为了解决这个问题,我改变了AVCaptureDevice的帧速率,就像这篇文章中的最后一个答案一样AVCapture capturing and getting framebuffer at 60 fps in iOS 7
为了使captureOutput函数以与摄像机相同的速度运行,您必须在更改AVCaptureDevice的帧速率之前添加AVCaptureDeviceInput。
以下是代码最终看起来像Swift 3的内容:
do{
input = try AVCaptureDeviceInput(device: backCamera)
if (error == nil && (captureSession?.canAddInput(input))!)
{
captureSession?.addInput(input)
}
var finalFormat = AVCaptureDeviceFormat()
var maxFPS: Double = 0
for vformat in (backCamera?.formats)!{
var ranges = (vformat as AnyObject).videoSupportedFrameRateRanges as! [AVFrameRateRange]
let frameRates = ranges[0]
if frameRates.maxFrameRate >= maxFPS && frameRates.maxFrameRate <= 120.0{
maxFPS = frameRates.maxFrameRate
finalFormat = vformat as! AVCaptureDeviceFormat
}
}
if maxFPS != 0{
let timeValue = Int64(1200.0 / maxFPS)
let timeScale: Int64 = 1200
try backCamera!.lockForConfiguration()
backCamera!.activeFormat = finalFormat
//print("CAMER FPS: \(backCamera?.activeFormat.videoSupportedFrameRateRanges.description)\n")
backCamera!.activeVideoMinFrameDuration = CMTimeMake(timeValue, Int32(timeScale))
backCamera!.activeVideoMaxFrameDuration = CMTimeMake(timeValue, Int32(timeScale))
backCamera!.focusMode = AVCaptureFocusMode.autoFocus
backCamera!.unlockForConfiguration()
}
}catch{
print("Problem setting FPS\n")
exit(0)
}