大佬教程收集整理的这篇文章主要介绍了AVCapture在iOS 7中捕获并获得60 fps的帧缓冲区,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
方法被称为只有15次,这意味着iPhone降级捕获输出到15 fps.
有没有人面临这样的问题?是否有可能增加捕获帧速率?
更新我的代码:
camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if([camera isTorchModeSupported:AVCaptureTorchModeOn]) { [camera lockForConfiguration:nil]; camera.torchMode=AVCaptureTorchModeOn; [camera unlockForConfiguration]; } [self configureCameraForHighestFrameRate:camera]; // Create a AVCaptureInput with the camera device NSError *error=nil; AVCaptureInput* cameraInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:&error]; if (cameraInput == nil) { NSLog(@"Error to create camera capture:%@",error); } // Set the output AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init]; // create a queue to run the capture on dispatch_queue_t capturequeue=dispatch_queue_create("capturequeue",null); // setup our delegate [videoOutput setSampleBufferDelegate:self queue:capturequeue]; // configure the pixel format videoOutput.videoSetTings = [NSDictionary DictionaryWithObjectsAndKeys:[NSnumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA],(id)kCVPixelBufferPixelFormatTypeKey,nil]; // Add the input and output [captureSession addInput:cameraInput]; [captureSession addOutput:videoOutput];
我在这里采用了configureCameraForHighestFrameRate方法https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html
您必须将AVCaptureSession设置为支持60 fps的格式:
AVsession = [[AVCaptureSession alloc] init]; AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; AVCaptureDeviceInput *capInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error]; if (capInput) [AVsession addInput:capInput]; for(AVCaptureDeviceFormat *vFormat in [videoDevice formats] ) { CMFormatDescriptionRef description= vFormat.formatDescription; float maxrate=((AVFrameRateRange*)[vFormat.videoSupportedFrameRateRanges objectATindex:0]).maxFrameRate; if(maxrate>59 && CMFormatDescriptionGetMediaSubType(description)==kCVPixelFormatType_420YpCbCr8BiPlanarFullRangE) { if ( YES == [videoDevice lockForConfiguration:NULL] ) { videoDevice.activeFormat = vFormat; [videoDevice setActiveVideoMinFrameDuration:CMTimeMake(10,600)]; [videoDevice setActiveVideoMaxFrameDuration:CMTimeMake(10,600)]; [videoDevice unlockForConfiguration]; NSLog(@"formats %@ %@ %@",vFormat.mediaType,vFormat.formatDescription,vFormat.videoSupportedFrameRateRanges); } } } prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: AVsession]; prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.view.layer addSublayer: prevLayer]; AVCaptureVideoDataOutput *videoOut = [[AVCaptureVideoDataOutput alloc] init]; dispatch_queue_t videoQueue = dispatch_queue_create("videoQueue",null); [videoOut setSampleBufferDelegate:self queue:videoQueue]; videoOut.videoSetTings = @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)}; videoOut.alwaysDiscardsLateVideoFrames=YES; if (videoOut) { [AVsession addOutput:videoOut]; videoConnection = [videoOut connectionWithMediaType:AVMediaTypeVideo]; }
如果您想使用AVAssetWriter写入一个文件,另外两个评论.不要使用pixelAdaptor,只需要添加样品
[videoWriterInput appendSampleBuffer:sampleBuffer]
其次,当设置assetwriter使用
[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSetTings:videoSetTings sourceFormatHint:formatDescription];
sourceFormatHint在写入速度方面有所不同.
以上是大佬教程为你收集整理的AVCapture在iOS 7中捕获并获得60 fps的帧缓冲区全部内容,希望文章能够帮你解决AVCapture在iOS 7中捕获并获得60 fps的帧缓冲区所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。