gpt4 book ai didi

ios - 将视频输出添加到 ARKit 应用

转载 作者:行者123 更新时间:2023-11-29 00:17:32 26 4
gpt4 key购买 nike

尝试使用 Apple 的 ARKitExample 应用快速制作增强现实应用的原型(prototype)。我一直在尝试添加一个按钮,让我可以保存屏幕上所有内容的视频。

我有一个 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 视频的正确方法

感谢帮助!

最佳答案

查看 Replay Kit ( https://developer.apple.com/documentation/replaykit )。

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

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

关于ios - 将视频输出添加到 ARKit 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44920005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com