将视频输出添加到 ARKit 应用程序



尝试使用 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视频的正确方法

感谢帮助!

查看重播套件 (https://developer.apple.com/documentation/replaykit(。

示例(不使用 SceneKit(位于 https://github.com/halmueller/ferries。

还可以考虑使用iOS 11的内置屏幕录制。

相关内容

  • 没有找到相关文章

最新更新