首页 > 解决方案 > 如何在 iOS 上录制视频时保存 TrueDepth 数据?

问题描述

我正在寻找一种在使用 TrueDepth 相机录制视频时将深度信息(对于每一帧)保存到文件中的方法。我找到了在拍照时保存深度数据的解决方案,而不是视频。

我目前有用于录制视频并将其保存到文件并同时捕获深度数据的代码。但是,我不知道如何保存深度数据。基本上我使用 AVCaptureSession 和 AVCaptureMovieFileOutput 来保存录制的视频。我发现深度数据是由 AVCaptureDepthDataOutput 给出的,但是如何将它保存到文件中呢?

代码的主要部分:

let captureSession = AVCaptureSession()
let sessionOutput = AVCapturePhotoOutput()
let movieOutput = AVCaptureMovieFileOutput()
let depthDataOutput = AVCaptureDepthDataOutput()

if let device = AVCaptureDevice.default(.builtInTrueDepthCamera,
                                 for: .video, position: .front) {
let input = try AVCaptureDeviceInput(device: device )

  if captureSession.canAddInput(input){
    captureSession.sessionPreset = AVCaptureSession.Preset.photo
    captureSession.addInput(input)
    if captureSession.canAddOutput(sessionOutput){   
      captureSession.addOutput(sessionOutput)
      // Code for adding previewing the video
    }
  }

  if captureSession.canAddOutput(depthDataOutput){
    captureSession.addOutput(depthDataOutput)
  }
  if let connection = depthDataOutput.connection(with: .depthData) {
    connection.isEnabled = true
    depthDataOutput.isFilteringEnabled = false
    print("Depth data working")
  } else {
    print("No AVCaptureConnection")
  }

  // Capture the video to a file
  captureSession.addOutput(movieOutput)
  captureSession.startRunning()

  // ...
  // How to store the depth data from AVCaptureDepthDataOutput ?
}

有任何想法吗?

标签: iosswiftiphone-xtruedepth-cameraiphone-xs

解决方案


推荐阅读