I'm trying to record a video at 120fps, in 640x480.
I can set the fps with:
// currentCamera is an AVCaptureDevice, session is an AVCaptureSession
let input = try AVCaptureDeviceInput(device: currentCamera)
session.addInput(input)
let targetFrameRate = CMTimeMake(1, 120)
if let slowMoFormat = currentCamera.formats
.flatMap({ return ($0 as? AVCaptureDeviceFormat) })
.filter({ format in
for x in format.videoSupportedFrameRateRanges {
if let range = x as? AVFrameRateRange {
if range.minFrameDuration <= targetFrameRate {
return true
}
}
}
return false
}).first {
try currentCamera.lockForConfiguration()
currentCamera.activeFormat = slowMoFormat
currentCamera.activeVideoMinFrameDuration = targetFrameRate
currentCamera.activeVideoMaxFrameDuration = targetFrameRate
currentCamera.unlockForConfiguration()
}
or the video size with
// session is an AVCaptureSession
session.sessionPreset = AVCaptureSessionPreset640x480
But I can't do both, since changing the activeFormat
, or session preset override the other change. Is there something obvious I'm missing?