I have a macos app that creates a sports scoreboard and streams this out in a third party streaming format. I need to use a library for this, which expects a CVPixelBuffer e.g. every 0.04 secs (25 fps). The scoreboard is a view with some subviews (scores, timers, etc) in an offscreen window. When a timer triggers to create a new frame, my code does:
• create a bitmap-representation for the view
• make a view.cacheDisplay(...)
• create a CIImage from the bitmap-representation
• create a CVPixelBuffer using CVPixelBufferCreate (kCVPixelFormatType_32BGRA format)
• render the CIImage into the CVPixelBuffer using ciContext.render(ciImage, to: pixelBufferOut)
• and finally hand over the CVPixelBuffer to the video library.
Works, the app is in production.
Now I come to the point where I need someone to tell me in which direction I have to think. The next feature requested is to do some animation for the scoreboard graphics , e.g. a simple "fade in" and "fade out". Later I would like to do more complex things, but let's just look at that. When I add a CABasicAnimation(keyPath: #keyPath(CALayer.opacity)) for fade in / fade out to the scoreboard base view (all views with layer), I can see it smoothly fading after I moved my offscreen to onscreen, so the animation works on screen. But in the video stream there is no animation, no fading, the content is shown with opacity 0.0 at one frame and in the next frame 1.0 (fade in) and the other way round for fade out. I have a not-animated, always visible text field displaying a timecode in the video screen and that shows every timecode in the video, so the frames are in fact generated, but contains no scoreboard view with an opacity other than 0 or 1.
How can I get the rendered frames from an animation? Is it somehow possible with Core Animation? Do I have to dig into Metal? I searched for hours to find something, but "animation" leads to discussions about animations on screen, while "video" is always about AVFoundation, but there is this library I have to use.
Thanks for any hints,
Nina