iOS 12 Swift将TrueDepth数据保存到视频

时间:2018-12-08 03:46:45

标签: ios swift quicktime avcapturemoviefileoutput truedepth-camera

我一直试图将TrueDepth数据写为快速播放的电影。我已经检查了https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/streaming_depth_data_from_the_truedepth_camera中的示例 我知道可以使用AVCaptureMovieFileOutput()来输出QuickTime电影,但是我不知道如何实现。我一直在尝试做一些简单的事情,例如仅将前置摄像头的捕获会话保存到快速时间。任何帮助,将不胜感激。这是我到目前为止的内容:

import UIKit
import AVFoundation

class ViewController: UIViewController {

    @IBOutlet weak var previewView: UIView!

    var captureSession:AVCaptureSession?
    var videoPreviewLayer:AVCaptureVideoPreviewLayer?
    var videoCaptureDevice: AVCaptureDevice?
    var input: AnyObject?

    var movieOutput = AVCaptureMovieFileOutput()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        videoCaptureDevice = AVCaptureDevice.default(.builtInTrueDepthCamera,
                                for: .video, position: .front)

        do {
            input = try AVCaptureDeviceInput(device: videoCaptureDevice!)
        } catch {
            print("video device error")
        }


        captureSession = AVCaptureSession()
        captureSession?.addInput(input as! AVCaptureInput)

        captureSession?.addOutput(movieOutput)

        videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
        videoPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
        videoPreviewLayer?.frame = previewView.layer.bounds
        previewView.layer.addSublayer(videoPreviewLayer!)
        captureSession?.startRunning()

    }

0 个答案:

没有答案