【问题标题】:AVCaptureSession capture output crashing (AVCaptureVideoDataOutput) in IOS7IOS7中的AVCaptureSession捕获输出崩溃(AVCaptureVideoDataOutput)
【发布时间】:2013-11-26 07:35:25
【问题描述】:

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 会发生这种情况,而在较低版本上它可以正常工作。 需要帮助你们。提前致谢。

【问题讨论】:

    标签: ios iphone objective-c ios7 avcapturesession


    【解决方案1】:

    对我来说,我删除了我在 viewDidUnload 方法中的会话中添加的所有音频和视频输入和输出,然后在此方法的任何行之前。现在它在所有 iOS 版本中都可以正常工作。

    对于删除输入/输出:

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

    【讨论】:

      猜你喜欢
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多