Recording SwiftUI View to video and playback

516 views Asked by At

Which frameworks can or should be used to record a SwiftUI view to a video (long) or gif file (short)? Both the user and the app can cause the view content to change, and then there are animations as well. CoreGraphics, MetalKit, AVFoundation, CoreVideo, CoreAnimation... AVAssetWriter,...

How about playback? If one SwiftUi view is used to playback video and another view to show a timeline or controls, then how can both views be kept in sync? Timer, CVDisplayLink/CADisplayLink,...

Lost in the woods here, please get me on the right track. Thanks!

1

There are 1 answers

0
Stephan Michels On

Maybe you can use NSHostingView.cacheDisplay(in:to:) to draw frames into NSBitmapImageReps and then use CoreGraphics to create an animated GIF using these frames. See for example NSImage+GIF.m