如何在RealityKit中录制视频? [英] How to record video in RealityKit?
问题描述
我在Xcode中有一个RealityKit项目,我想记录ARView
.我考虑过ReplayKit,但这是用于屏幕录像,我只想记录ARView
及其摄像机的提要.我考虑了AFathi的开源项目ARVideoKit,但是它不支持RealityKit ...关于不同渲染路径的一些知识.我找到了一篇中型文章,描述了如何在ARKit应用程序中实现录制功能,但是问题是它需要方法:func renderer(_ renderer: SCNSceneRenderer)
在RealityKit中不可用,因为它专门是SceneKit方法.
I have a RealityKit project in Xcode and I want to record the ARView
. I considered ReplayKit, but that is for screen recording, I want to record only the ARView
with its camera feed. I considered the open source project ARVideoKit by AFathi but that doesn't support RealityKit... something about different rendering paths. I have found a Medium article which describes how to implement a recording feature in an ARKit app, but the problem is that it requires the method: func renderer(_ renderer: SCNSceneRenderer)
which is not available in RealityKit because it is specifically a SceneKit method.
推荐答案
我的答案假定您熟悉使用AVAssetWriter
录制视频和音频.
My answer assumes you are familiar with recording video and audio using AVAssetWriter
.
ARKit session(_:didUpdate:)
方法的一部分提供了一个捕获的帧.返回的ARFrame
对象具有名为capturedFrame
的CVPixelBuffer
.像处理常规视频录制会话一样处理帧,除了不是在captureOutput(_:didOutput:from:)
方法中捕获,而是在此处捕获.如果您还打算从麦克风录制音频,则可能仍需要captureOutput(_:didOutput:from:)
音频方法.
There is a captured frame that is provided as part of the ARKit session(_:didUpdate:)
method. The ARFrame
object returned has a CVPixelBuffer
named capturedFrame
. Handle the frame as you would a regular video recording session, except instead of being captured in captureOutput(_:didOutput:from:)
method, it is captured here instead. You may still need a captureOutput(_:didOutput:from:)
method for audio if you intend on recording audio from the microphone, too.
就我而言,我将捕获的帧转换为MTLTexture
,并使用Metal处理视频帧,然后再将其传递到AVAssetWriter
.录制之前,我想在相机框架上画图.不幸的是,这样做很复杂,恐怕不是一个简短的复制+粘贴答案.希望将您指向ARKit返回的capturedFrame
对象是您开始的好地方.
In my case, I converted my captured frame into a MTLTexture
and used Metal to process my video frames before passing them to an AVAssetWriter
. I wanted to draw on top of my camera frames before recording. Unfortunately, doing this is very complicated and not a quick and short copy+paste answer I'm afraid. Hopefully pointing you to the capturedFrame
object returned by ARKit is a good place for you to start.
有关如何使用AVAssetWriter
录制视频的示例:
https://programmersought.com/article/80131041234/;jsessionid=38CBA6743FB3C440DE9D2B25A>
Example on how to record videos using AVAssetWriter
:
https://programmersought.com/article/80131041234/;jsessionid=38CBA6743FB3C440DE9D2B25A6854B28
如果要深入了解OpenGL/金属的兔子洞,请执行以下操作: https://developer.apple.com/documentation/metalkit/
If you want to dive down the rabbit hole of OpenGL/Metal: https://developer.apple.com/documentation/metalkit/
这篇关于如何在RealityKit中录制视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!