0

尝试使用 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

帮助表示赞赏!

4

1 回答 1

1

查看重播工具包 ( https://developer.apple.com/documentation/replaykit )。

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

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

于 2017-07-05T10:16:34.877 回答