首页 > 解决方案 > 如何使用 ARKit 和 SceneKit 录制屏幕?

问题描述

我想使用 ARKit 和 SceneKit 录制视频,但我可以保存来自 ARKit 的素材,但无法保存来自 SceneKit 的素材。我开始录制的代码如下:

    @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)")
        
    }
    
}

我结束录制的代码如下:

    @IBAction func stopRecording(sender: UIButton) {

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

}

由于我的代码运行而创建的视频链接是:屏幕录制

我无法从相机录制视频。如何解决我的录音问题?

标签: iosswiftscenekitarkit

解决方案


推荐阅读