How do I recording screens with ARKit and SceneKit?

Viewed 227

I want to record video using ARKit and SceneKit, but I can save footage from ARKit but can't save footage from SceneKit. My code that starts the recording is as follows:

    @IBAction func startRecording(sender: UIButton) {
    sender.backgroundColor = .red


    do {
        _ = try sceneView.startVideoRecording()
        
      guard let recorder = sceneView.recorder else { return }
      let captureSession = session

      guard let audioDevice = AVCaptureDevice.default(for: .audio) else { return }
      
      do {
        let captureInput = try AVCaptureDeviceInput(device: audioDevice)
        

        guard captureSession.canAddInput(captureInput) else { return }
     
        captureSession.addInput(captureInput)
        
      } catch {
        print("Can't create AVCaptureDeviceInput: \(error)")
        
      }
      guard captureSession.canAddRecorder(recorder) else { return }
      captureSession.addRecorder(recorder)
      captureSession.startRunning()
      self.captureSession = captureSession
        
    } catch {
        print("Something went wrong during video-recording preparation: \(error)")
        
    }
    
}

My code that ends the recording is as follows:

    @IBAction func stopRecording(sender: UIButton) {

    sender.backgroundColor = .white
        
    sceneView.finishVideoRecording { (recording) in
        print("Recoring Finished", recording.url)
        self.checkAuthorizationAndPresentActivityController(toShare: recording.url, using: self)
    }
    

}

The video link created as a result of my code running is:screen recording

I cannot record the video from the camera. How can I fix my problem with the recording?

0 Answers
Related