How to record video in RealityKit?

点点圈 提交于 2020-08-21 19:59:20

问题


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.


回答1:


My answer assumes you are familiar with recording video and audio using AVAssetWriter.

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.

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.

Example on how to record videos using AVAssetWriter: https://programmersought.com/article/80131041234/;jsessionid=38CBA6743FB3C440DE9D2B25A6854B28

If you want to dive down the rabbit hole of OpenGL/Metal: https://developer.apple.com/documentation/metalkit/



来源:https://stackoverflow.com/questions/59533059/how-to-record-video-in-realitykit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!