AVCaptureSession捕获输出在IOS7中崩溃(AVCaptureVideoDataOutput)

5
可能是重复问题:iPhone:AVCaptureSession捕获输出崩溃(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上出现了问题,而在低版本上却可以正常工作。希望大家能提供帮助。谢谢。

1个回答

2

对于我而言,在viewDidUnload方法中,在任何一行代码之前,我会移除在session中添加的所有音频和视频输入输出。现在它在所有iOS版本中都可以正常工作。

移除输入/输出:

[_captureSession removeInput:_captureDeviceInputAudio];
[_captureSession removeOutput:_captureOutputAudio];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接