title: AVCaptureSession capture output crashing (AVCaptureVideoDataOutput) in IOS7
body: <p>Possible duplicate of <a href="https://stackoverflow.com/questions/3331644/iphone-avcapturesession-capture-output-crashing-avcapturevideodataoutput">iPhone: AVCaptureSession capture output crashing (AVCaptureVideoDataOutput)</a></p>
  
  <p>I am created a app with custom camera whih is used for video recording. With the use of AVCaptureSession and AVCaptureVideoDataOutput, i got recorded video file. Every thing works fine for IOS 6 and lower version. but When i run the same app on device with IOS7 application is crash while deallocating the camera class with this issue...</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>The code which i am using for setting up the video data output --</p>
  
  <pre><code>[_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:&amp;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;
  </code></pre>
  
  <p>I didn't get why it is happening for IOS7 while on lower version it works fine.
  Need help you guys. Thanks in advance.</p>