- (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 deviceNSError *error=nil;AVCaptureinput* camerainput = [[AVCaptureDeviceinput alloc] initWithDevice:camera error:&error];if (camerainput == nil) { NSLog(@"Error to create camera capture:%@",error);}// Set the outputAVCaptureVIDeoDataOutput* vIDeoOutput = [[AVCaptureVIDeoDataOutput alloc] init];// create a queue to run the capture ondispatch_queue_t captureQueue=dispatch_queue_create("captureQueue",NulL);// setup our delegate[vIDeoOutput setSampleBufferDelegate:self queue:captureQueue];// configure the pixel formatvIDeoOutput.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
解决方法 我在iPhone 5上获得了60 fps的采样率,在iPhone 5上采用了120 fps,无论是在捕获输出中进行实时运动检测还是使用AVAssetWriter将帧保存到视频中.您必须将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的帧缓冲区所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)