我试图将设置为1080p的后置相机设置为60 FPS,但代码和教程会在设置fps之前循环显示相机格式。
有没有办法设置fps而不会在所有不同的格式中循环?它需要很长时间骑自行车,有时会崩溃。
下面是我的代码
func setFPS() {
captureSession = AVCaptureSession()
// var finalFormat = AVCaptureDevice.Format
var maxFps: Double = 0
for vFormat in backCamera!.formats
{
print("Tony active formats are: \(vFormat)")
var ranges = vFormat.videoSupportedFrameRateRanges as [AVFrameRateRange]
let frameRates = ranges[0]
if frameRates.maxFrameRate > 30
{
maxFps = frameRates.maxFrameRate
do {
try backCamera!.lockForConfiguration()
backCamera!.activeFormat = vFormat
backCamera!.activeVideoMinFrameDuration = CMTimeMake(1, 60)
backCamera!.activeVideoMaxFrameDuration = CMTimeMake(1, 60)
backCamera!.unlockForConfiguration()
print("Tony the Max FPS is \(maxFps) fps"); //prints 60 fps
// finalFormat = vFormat
}catch {
print("Error on frame rate")
}
}
}
print(String(maxFps) + " fps"); //prints 60 fps
print("Tony the FPS is \(backCamera!.activeVideoMaxFrameDuration.timescale) fps") //prints 60 fps
}