I've been trying to write TrueDepth data as a quicktime movie. I have examined the example from https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/streaming_depth_data_from_the_truedepth_camera I understand that it is possible to use AVCaptureMovieFileOutput() to output a quicktime movie, but I have no idea how to implement this. I have been trying to do something simple to start with such as just saving a capture session from the front facing camera to a quicktime. Any help would appreciated. This is what I have so far:
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()
}