I\'m new to AVCaptureSession and wish to better understand how to work with it. So I managed capturing the video stream as separated CIImages and convert them to UIImages. Now I
To set the capture session frame rate, you have to set it on the device using device.activeVideoMinFrameDuration and device.activeVideoMaxFrameDuration (if necessary).
In Swift 4 you can do something like this:
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)")
}
}
}
And call it
device.set(frameRate: 60)