Thanks @nilshg for your reply. However, if I just move the call to gif inside the loop, it will each time write the whole existing animation as a gif (overwriting) instead of appending to a preexisting gif.
Sorry I haven’t tried this myself and am on the phone but it seems to me the gif writes out the anim object with whatever frames are in it at that point in time - so if your loop adds to the anim object incrementally and you write it out every now
and then wouldn’t it just include all frames up to that point?
I might be missing something here but unless worrying the whole gif is super expensive it should be fine to just overwrite it every now and then?
Yes, that’s exactly what I meant and what seems to be the case.
I want to be able to write high resolution gifs; that is, one frame might reach the order of Megabytes and thus an animation from a simulation of multiple hours might reach the order of Gigabytes. Therefore, if the animation reaches Gigabytes, I cannot write out the whole animation each time.
When I need such a capability (fast incremental saving) I would just write multiple files that I later merge. What you want to do in general should be possible though I don’t know what is the right tool but in the mean time this generic workaround should work.
I believe that’s actually how Plots’ animations work — they write out their individual frames into a temporary directory and then punt to some external tool (I think Imagemagick or ffmpeg) that combines them into the gif.
FWIW, incrementally adding frames to a gif isn’t really a great match for the file format as there are a number of “whole movie” sorts of limitations/optimizations/compressions that require knowing about all frames — for example adding a frame that introduces a new color might require re-writing the header and all prior frames.
I absolutely get your points and agree. If I would consider only performance, then I would just write images and at the end create an animation. Yet, I am looking for some kind of interactivity, that is to conveniently be able to see what the simulation does while it is ongoing. So, I need to create/update an animation every now and then… and an incremental write to an animation seems a priory better then just to recreate the animation from scratch every time.
Would you know any movie file format that is better suited for incremental write?
Maybe it would work well for gif with a particular set of parameters? (Given that MATLAB has implemented the incremental gif write…)