尝试使用 Apple 的 ARKitExample 应用程序对增强现实应用程序进行快速原型设计。我一直在尝试添加一个按钮,该按钮允许我保存屏幕上所有内容的视频。
我AVCaptureSession
将其输入设备和输出文件配置为:
private let _session = AVCaptureSession()
配置
if let dualCameraDevice = AVCaptureDevice.default(.builtInDualCamera, for: AVMediaType.video, position: .back) {
defaultVideoDevice = dualCameraDevice
} else if let backCameraDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {
defaultVideoDevice = backCameraDevice
}
...
let videoDeviceInput = try AVCaptureDeviceInput(device: defaultVideoDevice!)
self._session.addInput(videoDeviceInput)
输出
let movieFileOutput = AVCaptureMovieFileOutput()
if self._session.canAddOutput(movieFileOutput) {
self._session.addOutput(movieFileOutput)
self._session.sessionPreset = AVCaptureSession.Preset.high
self.movieFileOutput = movieFileOutput
}
切换视频录制
guard let movieFileOutput = self.movieFileOutput else {
return
}
sessionQueue.async { [unowned self] in
if !movieFileOutput.isRecording {
if UIDevice.current.isMultitaskingSupported {
self.backgroundRecordingID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
}
connection before starting recording.
let movieFileOutputConnection = self.movieFileOutput?.connection(with: AVMediaType.video)
//
let availableVideoCodecTypes = movieFileOutput.availableVideoCodecTypes as [AVVideoCodecType]
if availableVideoCodecTypes.contains(.hevc) {
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: movieFileOutputConnection!)
}
// Start recording to a temporary file.
let outputFileName = NSUUID().uuidString
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
movieFileOutput.startRecording(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
} else {
//-- THIS NEVER EXECS -->>>>
movieFileOutput.stopRecording()
}
}
movieFileOutput.stopRecording()
movileFileOutput.isRecording
永远不会像遗骸一样接到电话false
不确定这是否是捕获视频的正确方法ARSCNView
帮助表示赞赏!