title: Adding video output to ARKit app
body: <p>Trying to fast-prototype an Augmented reality app by using the ARKitExample app from Apple. I've been trying to add a button that allows me to save a video of everything is on the screen.</p>
  
  <p>I've a <code>AVCaptureSession</code> configured with its input device and output file as:</p>
  
  <pre><code>private let _session = AVCaptureSession()
  </code></pre>
  
  <p>configuration</p>
  
  <pre><code>    if let dualCameraDevice = AVCaptureDevice.default(.builtInDualCamera, for: AVMediaType.video, position: .back) {
        defaultVideoDevice = dualCameraDevice
      } else if let backCameraDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {
       defaultVideoDevice = backCameraDevice
      } 
              ...    
      let videoDeviceInput = try AVCaptureDeviceInput(device: defaultVideoDevice!)
  self._session.addInput(videoDeviceInput)
  </code></pre>
  
  <p>output </p>
  
  <pre><code>let movieFileOutput = AVCaptureMovieFileOutput()
  
  if self._session.canAddOutput(movieFileOutput) {
   self._session.addOutput(movieFileOutput)
   self._session.sessionPreset = AVCaptureSession.Preset.high
  
   self.movieFileOutput = movieFileOutput
  }
  </code></pre>
  
  <p>toggling video recording</p>
  
  <pre><code>guard let movieFileOutput = self.movieFileOutput else {
              return
          }
  
  
          sessionQueue.async { [unowned self] in
              if !movieFileOutput.isRecording {
                  if UIDevice.current.isMultitaskingSupported {
  
                      self.backgroundRecordingID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
                  }
  
                  connection before starting recording.
                  let movieFileOutputConnection = self.movieFileOutput?.connection(with: AVMediaType.video)
  
  //
                  let availableVideoCodecTypes = movieFileOutput.availableVideoCodecTypes as [AVVideoCodecType]
  
                  if availableVideoCodecTypes.contains(.hevc) {
                      movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: movieFileOutputConnection!)
                  }
  
                  // Start recording to a temporary file.
                  let outputFileName = NSUUID().uuidString
                  let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
                  movieFileOutput.startRecording(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
  
  
              } else {
  //-- THIS NEVER EXECS --&gt;&gt;&gt;&gt;
                      movieFileOutput.stopRecording()
                  }
              }
  </code></pre>
  
  <p><code>movieFileOutput.stopRecording()</code> never gets call as <code>movileFileOutput.isRecording</code> remains as <code>false</code></p>
  
  <p>Not sure whether this is the proper way to capture video of a <code>ARSCNView</code></p>
  
  <p>Help is appreciated! </p>