title: Simultaneous AVCaptureVideoDataOutput and AVCaptureMovieFileOutput
body: <p>I need to be able to have <code>AVCaptureVideoDataOutput</code> and <code>AVCaptureMovieFileOutput</code> working at the same time. The below code works, however, the video recording does not. The <code>didFinishRecordingToOutputFileAtURL</code> delegate is called directly after <code>startRecordingToOutputFileURL</code> is called. Now if i remove <code>AVCaptureVideoDataOutput</code> from the 
  <code>AVCaptureSession</code> by simply commenting out the line:</p>
  
  <p><code>[captureSession addOutput:captureDataOutput];</code> </p>
  
  <p>The video recording works but then the SampleBufferDelegate is not called (which i need).</p>
  
  <p>How can i go about having <code>AVCaptureVideoDataOutput</code> and <code>AVCaptureMovieFileOutput</code> working simultaneously. </p>
  
  <pre><code>- (void)initCapture {
   AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] error:NULL]; 
  
   captureDataOutput = [[AVCaptureVideoDataOutput alloc] init]; 
   [captureDataOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; 
  
   m_captureFileOutput = [[AVCaptureMovieFileOutput alloc] init];
  
   NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 
   NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; 
   NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; 
  
   [captureDataOutput setVideoSettings:videoSettings]; 
  
   captureSession = [[AVCaptureSession alloc] init]; 
  
   [captureSession addInput:captureInput];
   [captureSession addOutput:m_captureFileOutput]; 
   [captureSession addOutput:captureDataOutput]; 
  
   [captureSession beginConfiguration]; 
   [captureSession setSessionPreset:AVCaptureSessionPresetLow]; 
   [captureSession commitConfiguration]; 
  
   [self performSelector:@selector(startRecording) withObject:nil afterDelay:10.0];
   [self performSelector:@selector(stopRecording) withObject:nil afterDelay:15.0];
  
   [captureSession startRunning];
  }
  
  
  - (void) startRecording
  {
      [m_captureFileOutput startRecordingToOutputFileURL:[self tempFileURL] recordingDelegate:self];
  
  }
  
  - (void) stopRecording
  {
      if([m_captureFileOutput isRecording])
   [m_captureFileOutput stopRecording];
  
  }
  
  
  - (NSURL *) tempFileURL
  {
   NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"camera.mov"];
   NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
   NSFileManager *fileManager = [NSFileManager defaultManager];
   if ([fileManager fileExistsAtPath:outputPath]) {
    [[NSFileManager defaultManager] removeItemAtPath:outputPath error:nil];
   [outputPath release];
   return [outputURL autorelease];
  }
  
  
  
  - (void)captureOutput:(AVCaptureFileOutput *)captureOutput didStartRecordingToOutputFileAtURL:(NSURL *)fileURL fromConnections:(NSArray *)connections
  {
   NSLog(@"start record video");
  }
  
  - (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
  {
   NSLog(@"end record");
  }
  
  
  - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 
  { 
        // do stuff with sampleBuffer
  }
  </code></pre>
  
  <p>I should add i am getting the error:</p>
  
  <pre><code>Error Domain=NSOSStatusErrorDomain Code=-12780 "The operation couldn’t be completed. (OSStatus error -12780.)" UserInfo=0x23fcd0 {AVErrorRecordingSuccessfullyFinishedKey=false}
  </code></pre>
  
  <p>from</p>
  
  <pre><code>- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
  </code></pre>
  
  <p>Cheers</p>