我正在尝试以 640x480 的 120fps 录制视频。
我可以设置fps:
// 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()
}
或视频大小
// session is an AVCaptureSession
session.sessionPreset = AVCaptureSessionPreset640x480
但我不能两者都做,因为更改activeFormat
, 或 session 预设会覆盖其他更改。我有什么明显的遗漏吗?