Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何以240fps的速度调用captureOutput?_Ios_Swift_Objective C_Avfoundation - Fatal编程技术网

Ios 如何以240fps的速度调用captureOutput?

Ios 如何以240fps的速度调用captureOutput?,ios,swift,objective-c,avfoundation,Ios,Swift,Objective C,Avfoundation,我想以高帧速率保存图像。 IO很贵,不是240fps,但可能超过120fps 我要做的是在viewDidLoad中设置capturedivice, 并在captureOutput中记录时间戳并查看速率 但我注意到captureOutput总是30fps。 你能告诉我哪一个我错了吗 谢谢你的时间和回答 以下是我的代码和结果: // //ViewController.swift //定制摄像机 // //由chunibyo于2021/3/8创建。 // 导入UIKit 进口AVF基金会 进口视觉 导

我想以高帧速率保存图像。 IO很贵,不是240fps,但可能超过120fps

我要做的是在
viewDidLoad
中设置capturedivice, 并在
captureOutput
中记录时间戳并查看速率

但我注意到captureOutput总是30fps。 你能告诉我哪一个我错了吗

谢谢你的时间和回答

以下是我的代码和结果:

//
//ViewController.swift
//定制摄像机
//
//由chunibyo于2021/3/8创建。
//
导入UIKit
进口AVF基金会
进口视觉
导入视频工具箱
类ViewController:UIViewController、AVCaptureVideoDataOutputSampleBufferDelegate{
@IBOutlet弱var captureButton:UIButton!
让sessionQueue=DispatchQueue(标签:“会话队列”)
var状态=错误
私有var MyCaptureDevice:AVCaptureDevice?
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后执行任何其他设置。
captureButton.layer.cornerRadius=captureButton.frame.width/2
captureButton.layer.masksToBounds=true
captureButton.layer.zPosition=10
guard let captureDevice=AVCaptureDevice.default(.builtinualCamera,for:.视频,position:.返回)else{return}
guard let input=try?AVCaptureDeviceInput(设备:captureDevice)else{return}
// 1
对于captureDevice.formats中的vFormat{
// 2
让ranges=vFormat.videoSupportedFrameRateRanges为[AVFrameRateRange]
设帧率=范围[0]
// 3
如果frameRates.maxFrameRate==240{
// 4
try?captureDevice.lockForConfiguration()
captureDevice.activeFormat=vFormat作为AVCaptureDevice.Format
captureDevice.activeVideoMinFrameDuration=CMTimeMake(值:1,时间刻度:Int32(240))
captureDevice.activeVideoMaxFrameDuration=CMTimeMake(值:1,时间刻度:Int32(240))
captureDevice.videoZoomFactor=captureDevice.minAvailableVideoZoomFactor
captureDevice.unlockForConfiguration()的
}
}
设captureSession=AVCaptureSession();
//captureSession.sessionPreset=.photo
captureSession.addInput(输入)
captureSession.startRunning();
让previewLayer=AVCaptureVideoPreviewLayer(会话:captureSession)
view.layer.addSublayer(预览层)
previewLayer.frame=view.frame
让dataOutput=AVCaptureVideoDataOutput()
dataOutput.setSampleBufferDelegate(self,队列:DispatchQueue(标签:“videoQueue”))
dataOutput.alwaysDiscardsLateVideoFrames=true;
captureSession.addOutput(数据输出)
打印(captureDevice.minAvailableVideoZoomFactor)
打印(captureDevice.maxAvailableVideoZoomFactor)
MyCaptureDevice=captureDevice
}
func captureOutput(\uOutput:AVCaptureOutput,didOutput sampleBuffer:CMSampleBuffer,from connection:AVCaptureConnection){
打印(CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)))
//如果!状态{return}
//guard let pixelBuffer:CVPixelBuffer=CMSampleBufferGetImageBuffer(sampleBuffer)else{return}
//guard let uiImage=uiImage(pixelBuffer:pixelBuffer)else{return}
//
//sessionQueue.async{
//guard let captureDevice=self.MyCaptureDevice else{return}
//如果captureDevice.videoZoomFactor>=(captureDevice.maxAvailableVideoZoomFactor-0.2){return}
//UIImageWriteToSavedPhotosAlbum(uiImage,无,无,无)
//try?captureDevice.lockForConfiguration()
//captureDevice.videoZoomFactor+=0.1
//captureDevice.unlockForConfiguration()的
//        }
}
@iAction func captureControl(\发送方:UIButton){
DispatchQueue.main.async{
如果是自我状态{
self.captureButton.backgroundColor=.white
打印(“停止”)
self.status=!self.status
}
否则{
self.captureButton.backgroundColor=.red
打印(“录制…”)
self.status=!self.status
}
}
}
}
扩展UIImage{
公共便利初始化?(pixelBuffer:CVPixelBuffer){
cgImage:cgImage?
VTCreateCImageFromCVPixelBuffer(pixelBuffer,选项:nil,imageOut:&cgImage)
guard let_cgImage=cgImage else{return nil}
self.init(cgImage:\u cgImage)
}
}

(对不起,stackoverflow不允许我发布图像)

captureOutput
仅日志为240fps


captureOutput
向相册拍照的速度约为70~100fps

这段代码可以获得240fps的日志

//
//ViewController.swift
//定制摄像机
//
//由chunibyo于2021/3/8创建。
//
导入UIKit
进口AVF基金会
进口视觉
导入视频工具箱
类ViewController:UIViewController、AVCaptureVideoDataOutputSampleBufferDelegate{
@IBOutlet弱var captureButton:UIButton!
让sessionQueue=DispatchQueue(标签:“会话队列”)
var状态=错误
var zoomStatus=1
私有var MyCaptureDevice:AVCaptureDevice?
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后执行任何其他设置。
captureButton.layer.cornerRadius=captureButton.frame.width/2
captureButton.layer.masksToBounds=true
captureButton.layer.zPosition=10
guard let captureDevice=AVCaptureDevice.default(对于:AVMediaType.video)else{return}
guard let input=try?AVCaptureDeviceInput(设备:captureDevice)else{return}
设captureSession=AVCaptureSession();
//captureSession.sessionPreset=.pho