How to record video in RealityKit?

前端 未结 1 1630
春和景丽
春和景丽 2021-02-04 16:48

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 ARVi

1条回答
  •  渐次进展
    2021-02-04 17:22

    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/

    0 讨论(0)
提交回复
热议问题