I have an animation which consists of 250 frames. Each frame is 1080x1920 resolution and in PNG format. I need to take all these frames, animate them with CAKeyframeAnimation
and render them on a video using AVFoundation
tools.
The issue arises when I try to create a values
array for CAKeyframeAnimation
. Initializing 250 FullHD images causes quite a big memory spike, which system detects and decides to kill the app.
I've tried playing with autoreleasepool
but it doesn't seem to help at all (no wonder, because CAKeyframeAnimation
needs to hold on those images).
The problem goes even further: I actually have 10 of such animations! And I need to quickly switch between them because the app allows to preview those animations dynamically (which is done via AVSynchronizedLayer
) before exporting everything in a video file.
So my question is: how can I load a big array of UIImage
instances without system killing the app because of a memory surge? Is there an asynchronous way of loading them?