iPhone: AVCaptureSession capture output crashing (AVCaptureVideoDataOutput)
可能重复我创建了一个带有自定义相机的应用程序,用于视频录制。通过使用AVCaptureSession和AVCaptureVideoDataOutput,我得到了录制的视频文件。对于IOS 6和更低版本,每件事都可以正常工作。但当我在设备上运行相同的应用程序与IOS7应用程序崩溃同时解决相机类与此问题...
thread #1: tid = 0x7994, 0x3b1eab26 libobjc.A.dylib`objc_msgSend + 6, stop reason = EXC_BAD_ACCESS (code=1, address=0x7000000c)
frame #0: 0x3b1eab26 libobjc.A.dylib`objc_msgSend + 6
frame #1: 0x2fa46654 AVFoundation`-[AVCaptureVideoDataOutput _applyOverridesToCaptureOptions:] + 172
frame #2: 0x3387b050 UIKit` stub helpers + 27224
我用来设置视频数据输出的代码 -
[_captureSession beginConfiguration];
if([_captureSession canAddInput:_captureDeviceInputAudio])
[_captureSession addInput:_captureDeviceInputAudio];
_captureOutputAudio = [[AVCaptureAudioDataOutput alloc] init] ;
if([_captureSession canAddOutput:_captureOutputAudio])
[_captureSession addOutput:_captureOutputAudio];
_captureDeviceVideo = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
_captureDeviceInputVideo = [AVCaptureDeviceInput deviceInputWithDevice:_captureDeviceVideo error:&error];
if([_captureSession canAddInput:_captureDeviceInputVideo])
[_captureSession addInput:_captureDeviceInputVideo];
_captureOutputVideo = [[AVCaptureVideoDataOutput alloc] init] ;
if([_captureSession canAddOutput:_captureOutputVideo])
[_captureSession addOutput:_captureOutputVideo];
[_captureOutputAudio setSampleBufferDelegate:self queue:_captureVideoDispatchQueue];
[_captureOutputVideo setSampleBufferDelegate:self queue:_captureVideoDispatchQueue];
dispatch_release(_captureSessionDispatchQueue);
dispatch_release(_captureVideoDispatchQueue);
NSString *sessionPreset = [_captureSession sessionPreset];
AVCaptureConnection *videoConnection = [_captureOutputVideo connectionWithMediaType:AVMediaTypeAudio];
[self _setOrientationForConnection:videoConnection];
// setup stabilization, if available
if ([videoConnection isVideoStabilizationSupported])
[videoConnection setEnablesVideoStabilizationWhenAvailable:YES];
// setup pixel format
NSDictionary *videoSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange], (id)kCVPixelBufferPixelFormatTypeKey,
nil];
[_captureOutputVideo setVideoSettings:videoSettings];
// discard late frames
[_captureOutputVideo setAlwaysDiscardsLateVideoFrames:NO];
// setup video to use 640 x 480 for the hightest quality touch-to-record
if ( [_captureSession canSetSessionPreset:AVCaptureSessionPreset640x480] )
sessionPreset = AVCaptureSessionPreset640x480;
// set the framerate and preset
CMTime frameDuration = CMTimeMake( 1, 30 );
if ( videoConnection.supportsVideoMinFrameDuration )
videoConnection.videoMinFrameDuration = frameDuration; // needs to be applied to session in iOS 7
if ( videoConnection.supportsVideoMaxFrameDuration )
videoConnection.videoMaxFrameDuration = frameDuration;
我不明白为什么IOS7会发生这种情况,而在较低版本上它运行正常。 需要帮助你们。提前谢谢。
答案 0 :(得分:2)
对我来说,我删除了在此方法中的任何行之前在viewDidUnload方法中添加的所有音频和视频输入和输出。现在它在所有IOS版本中都运行良好。 用于删除输入/输出
[_captureSession removeInput:_captureDeviceInputAudio];
[_captureSession removeOutput:_captureOutputAudio];