iOS 9以每秒60帧的速度录制视频
正在尝试使用AVFoundation和Swift以每秒60帧的速度录制视频,但下面的代码不起作用。即使设置了60fps,视频仍以30fps的速度录制iOS 9以每秒60帧的速度录制视频,ios,swift,avfoundation,Ios,Swift,Avfoundation,正在尝试使用AVFoundation和Swift以每秒60帧的速度录制视频,但下面的代码不起作用。即使设置了60fps,视频仍以30fps的速度录制 captureSession = AVCaptureSession() var finalFormat = AVCaptureDeviceFormat() var maxFps: Double = 0 for vFormat in camera!.formats { var ranges = vFormat.videoSuppo
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()
captureSession=AVCaptureSession()
var finalFormat=AVCaptureDeviceFormat()
var maxFps:Double=0
对于摄像机中的vFormat!。格式
{
var ranges=vFormat.videoSupportedFrameRateRanges as![AVFrameRateRange]
设帧率=范围[0]
如果frameRates.maxFrameRate>=maxFps&&frameRates.maxFrameRate在创建AVCaptureDeviceInput后设置相机属性有效
let video = try AVCaptureDeviceInput(device: camera) as AVCaptureDeviceInput
captureSession!.addInput(video)
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()
你知道只有iphone 6或更高版本才有这个功能,对吗?是的。我正在用iphone 6S进行测试。该设备使用本机摄像头,以60fps的速度进行记录?是的。用ipad和iphone进行了测试。