title: Error recording to movie file with AVFoundation
body: <p>This is a strange problem.  I have not changed any code involving this in my project but my video recording has randomly stopped working.  When I try to save to a movie to a file I get the following error: </p>
  
  <p><strong>Error Domain=NSOSStatusErrorDomain Code=-12780 "The operation couldn’t be completed. (OSStatus error -12780.)"</strong></p>
  
  <p>I start my capture with the following code:</p>
  
  <pre><code>- (void)initVideoCapture {
  self.captureSession = [[AVCaptureSession alloc] init];
  
  AVCaptureDevice *videoCaptureDevice = [self frontFacingCameraIfAvailable];
  AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:nil];
  [self.captureSession addInput:videoInput];
  
  aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];    
  [self.captureSession addOutput:aMovieFileOutput];
  [self detectVideoOrientation:aMovieFileOutput];
  
  [self.captureSession setSessionPreset:AVCaptureSessionPresetMedium];
  
  [self.captureSession startRunning];
  </code></pre>
  
  <p>}</p>
  
  <p>I then call this method from the viewController to start recording:</p>
  
  <pre><code>- (void) startRecord {
  NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
  [outputFormatter setDateFormat:@"yyyyMMddHHmmss"];
  NSString *newDateString = [outputFormatter stringFromDate:[NSDate date]];
  [outputFormatter release];
  
  NSString * fileString = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mov",newDateString]];
  recordFileURL = [[NSURL alloc] initFileURLWithPath:fileString];        
  
  [aMovieFileOutput startRecordingToOutputFileURL:recordFileURL recordingDelegate:self];
  </code></pre>
  
  <p>}</p>
  
  <p>At this time I get the error in this function. </p>
  
  <blockquote>
    <ul>
    <li>(void)captureOutput:(AVCaptureFileOutput *)captureOutput
    didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
    fromConnections:(NSArray *)connections error:(NSError *)error</li>
    </ul>
  </blockquote>
  
  <p>What is really weird is that it randomly works sometimes.  Like, I will compile the project and it will work 100% of the time.  Next time I compile it will work 0%.  What could I be doing wrong?  Anything obvious?</p>