使用 ARKIT 拍摄视频 [英] Take a Video with ARKIT

查看:27
本文介绍了使用 ARKIT 拍摄视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好社区

我尝试使用 Swift 4 和即将推出的出色ARKit-Framework 构建应用程序,但我被卡住了.我需要视频与框架或至少一个 UIImage 序列,但我不知道如何.

I try to build a App with Swift 4 and the great upcoming ARKit-Framework but I am stuck. I need to take a Video with the Framework or at least a UIImage-sequence but I dont know how.

这是我尝试过的:

在 ARKit 中,您有一个会话来跟踪您的世界.此会话有一个 capturedImage 实例,您可以在其中获取当前图像.所以我创建了一个 Timer,它将 capturedImage 每 0.1s 附加到一个列表中.这对我有用,但是如果我通过单击开始"按钮启动计时器,相机开始滞后.我猜这与计时器无关,因为如果我通过单击停止"按钮使计时器无效,则相机再次流畅.

In ARKit you have a session which tracks your world. This session has a capturedImage instance where you can get the current Image. So I createt a Timer which appends the capturedImage every 0.1s to a List. This would work for me but If I start the Timer by clicking a "start"-button, the camera starts to lag. Its not about the Timer i guess because If I invalidate the Timer by clicking a "stop"-button the camera is fluent again.

有没有办法解决滞后甚至更好的方法?

Is there a way to solve the lags or even a better way?

谢谢

推荐答案

我能够使用 ReplayKit 就是这样做的.

I was able to use ReplayKit to do exactly that.

在您的 iOS 设备上,转到设置 -> 控制中心 -> 自定义控件.将屏幕录制"移动到包括"部分,然后向上滑动以调出控制中心.您现在应该会看到圆形的屏幕录制图标,您会注意到当您按下它时,iOS 开始录制您的屏幕.点击蓝色条将结束录制并将视频保存到照片.

On your iOS device, go to Settings -> Control Center -> Customize Controls. Move "Screen Recording" to the "Include" section, and swipe up to bring up Control Center. You should now see the round Screen Recording icon, and you'll notice that when you press it, iOS starts to record your screen. Tapping the blue bar will end recording and save the video to Photos.

使用 ReplayKit,您可以让您的应用调用屏幕录像机并捕获您的 ARKit 内容.

Using ReplayKit, you can make your app invoke the screen recorder and capture your ARKit content.

开始录制:

RPScreenRecorder.shared().startRecording { error in
    // Handle error, if any
}

停止录制:

RPScreenRecorder.shared().stopRecording(handler: { (previewVc, error) in
    // Do things
})

录制完成后,.stopRecording 会为您提供一个可选的 RPPreviewViewController,即

After you're done recording, .stopRecording gives you an optional RPPreviewViewController, which is

显示用户界面的对象,用户可以在其中预览和编辑使用 ReplayKit 创建的屏幕录制.

An object that displays a user interface where users preview and edit a screen recording created with ReplayKit.

所以在我们的例子中,如果不是 nil,你可以显示 previewVc

So in our example, you can present previewVc if it isn't nil

RPScreenRecorder.shared().stopRecording(handler: { (previewVc, error) in
    if let previewVc = previewVc {
        previewVc.delegate = self
        self.present(previewVc, animated: true, completion: nil)
    }
})

您可以直接从 previewVc 编辑和保存视频,但您可能希望让自己(或某人)成为 RPPreviewViewControllerDelegate,因此您可以在完成后轻松关闭 previewVc.

You'll be able to edit and save the vide right from the previewVc, but you might want to make self (or someone) the RPPreviewViewControllerDelegate, so you can easily dismiss the previewVc when you're finished.

extension MyViewController: RPPreviewViewControllerDelegate {
    func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
        // Called when the preview vc is ready to be dismissed
    }
}

注意事项

您会注意到 startRecording 将记录应用程序显示",因此如果您拥有的任何视图(按钮、标签等)也将被记录. 我发现在录制时隐藏控件并让我的用户知道点击屏幕会停止录制很有用,但我也读到其他人成功地将他们的基本控件放在单独的 UIWindow 上.

单独的 UIWindow 技巧有效.我能够制作一个覆盖窗口,在那里我有一个记录按钮和一个计时器,但这些没有被记录下来.

The separate UIWindow trick works. I was able to make an overlay window where I had my a record button and a timer and these weren't recorded.

let overlayWindow = UIWindow(frame: view.frame)
let recordButton = UIButton( ... )
overlayWindow.backgroundColor = UIColor.clear

UIWindow 默认是隐藏的.所以当你想显示你的控件时,你必须将 isHidden 设置为 false.

The UIWindow will be hidden by default. So when you want to show your controls, you must set isHidden to false.

祝你好运!

这篇关于使用 ARKIT 拍摄视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆