title: Recording video with AVCaptureSession
body: <p>I'm trying to record a video using AVCaptureSession and AVCaptureMovieFileOutput but whenever I try to <i>start</i> recording I get this error in the <code>didFinishRecordingToOutputFileAtURL</code> AVCaptureFileOutputRecordingDelegate method.</p>
  
  <pre><code>Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x15de7c40 {AVErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedDescription=The operation could not be completed, NSLocalizedFailureReason=An unknown error occurred (-12673), NSUnderlyingError=0x15d88aa0 "The operation couldn’t be completed. (OSStatus error -12673.)"}
  </code></pre>
  
  <p>This is the code I'm using to add the AVCaptureMovieFileOutput and initialise my AVCaptureSession</p>
  
  <pre><code>- (AVCaptureSession *)session {
      if (!_session) {
          _session = [[AVCaptureSession alloc] init];
  
  
          // ADD CAMERA DEVICE
          NSError *error = nil;
          AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:self.videoDevice error:&amp;error];
          if (!videoInput) {
              NSLog(@"ERROR: trying to open camera: %@", error);
          } else {
              [_session addInput:videoInput];
          }
  
  
          // ADD AUDIO DEVICE
          error = nil;
          AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:self.audioDevice error:&amp;error];
          if (!audioInput)
          {
              NSLog(@"ERROR: trying to open mic: %@", error);
          } else {
              [_session addInput:audioInput];
          }
  
  
          // ADD OUTPUT FILE
          if ([_session canAddOutput:self.movieFileOutput]) {
              [_session addOutput:self.movieFileOutput];
          }
  
  
          [_session startRunning];
      }
  
      return _session;
  }
  </code></pre>
  
  <p>My AVCaptureMovieFileOutput is lazy loaded like this</p>
  
  <pre><code>- (AVCaptureMovieFileOutput *)movieFileOutput {
      if (!_movieFileOutput) {
          _movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
  
          Float64 TotalSeconds = 60;          //Total seconds
          int32_t preferredTimeScale = 30;    //Frames per second
          CMTime maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale);
          _movieFileOutput.maxRecordedDuration = maxDuration;
          _movieFileOutput.minFreeDiskSpaceLimit = 1024 * 1024;
      }
  
      return _movieFileOutput;
  }
  </code></pre>
  
  <p>I'm not sure what I'm doing wrong as most of the tutorials I've seen do it this way.</p>
  
  <p>Thanks</p>