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会发生这种情况,而在较低版本上它可以正常工作。你们需要帮助。预先感谢。
对我来说,我删除了在此方法的任何行之前在viewDidUnload方法中添加到会话上的所有音频和视频输入和输出。现在,它在所有iOS版本中均可正常运行。
用于删除输入/输出:
[_captureSession removeInput:_captureDeviceInputAudio];
[_captureSession removeOutput:_captureOutputAudio];