0
試圖使用AVFoundation和Swift以60fps記錄視頻,但下面的代碼無法正常工作。即使60fps設置,視頻仍然以30fps記錄。iOS 9以60fps記錄視頻
captureSession = AVCaptureSession()
var finalFormat = AVCaptureDeviceFormat()
var maxFps: Double = 0
for vFormat in camera!.formats
{
var ranges = vFormat.videoSupportedFrameRateRanges as! [AVFrameRateRange]
let frameRates = ranges[0]
if frameRates.maxFrameRate >= maxFps && frameRates.maxFrameRate <= 60
{
maxFps = frameRates.maxFrameRate
finalFormat = vFormat as! AVCaptureDeviceFormat
}
}
print(String(maxFps) + " fps"); //prints 60 fps
try camera!.lockForConfiguration()
camera!.activeFormat = finalFormat
camera!.activeVideoMinFrameDuration = CMTimeMake(1, 60)
camera!.activeVideoMaxFrameDuration = CMTimeMake(1, 60)
camera!.unlockForConfiguration()
let video = try AVCaptureDeviceInput(device: camera) as AVCaptureDeviceInput
captureSession!.addInput(video)
let audio = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)) as AVCaptureDeviceInput
captureSession!.addInput(audio)
fileOutput = AVCaptureMovieFileOutput()
captureSession?.addOutput(fileOutput)
captureSession!.startRunning()
你知道,只有iphone 6或更新的,有這個功能,對不對? – UlyssesR
是的。我正在測試iphone 6s – user2800679
該設備,使用本機相機,記錄在60fps? – UlyssesR