Creating gifs with Makie is much slower than creating mp4s

I’ve noticed that when creating relatively large movies using Makie.jl, saving them to .gif is significantly slower (several times) than saving to .mp4. I tried profiling the plotting script, and found that in both cases almost all the time is spent in the ‘ccall’ - I guess that’s in FFMPEG?

Does anyone know if there might be a way to speed up saving to .gif? Is it just expected that making gifs should be several times slower than making mp4s? I have a workflow that I’m happy with using gifs (e.g. comparing multiple files frame by frame) that I don’t want to spend the effort to reproduce working with mp4 files unless I really have to!

An animated GIF isn’t really a video, it’s just a series of still images, whereas a video file usually encodes the differences between successive frames. So, depending on the nature of the content, I’d expect the GIF to be larger and to take longer to make, than a true video.

A Makie expert may come along with a better answer though… :grinning:

I’ll be happy to help here, It might just be that quantization that happen on images is more complicated so each image takes much longer, ending up with long cumulative times. I doubt FFMPEG is going to be a great sol, maybe try ImageMagick.jl too and if not GIFImages.jl(which is 13x faster compared to ImageMagick.jl)

I doubt FFMPEG is going to be a great sol, maybe try ImageMagick.jl too and if not GIFImages.jl(which is 13x faster compared to ImageMagick.jl)

Thanks for the suggestion. Makie.record which uses ffmpeg
records a 20 MiB gif in 15 s here
(by the way, changing the extension to .mp4 produces a 1.5 MiB mp4 in 10 s).
But GIFImages.gif_encode is actually slightly slower in this case:

# animation_file is the gif produced by Makie in 15 s
img2 = gif_decode(animation_file)  # 2.1 s
1104×1166×121 Array{RGB{N0f8},3} with eltype RGB{FixedPointNumbers.N0f8}:

gif_encode("animation2.gif", img2)  # 20.9 s

So it looks like mp4 is a clear winner in this case (both in speed and size),
but there might be room for improvement ?

Thanks everyone.

I’ve been digging some more into the issue I have. It seems like it’s actually a problem when saving gifs from Makie while passing -O3 and/or --check-bounds=no flags to julia… The ‘optimised’ build is spending a long time in some function called issupported(). I’m going to poke a bit more and probably open an issue on the Makie github…

It looks like my actual problem was that I used the --check-bounds=no flag, which can now (since julia-1.9.0) cause performance problems by making type-inference fail. That flag caused me about a 5x slow-down, which had made me question what was taking so long to create gifs (compared to previous experience using Plots.jl). For a bit more info, see Slowdown when using `--check-bounds=no` on julia-1.9.x · Issue #3132 · MakieOrg/Makie.jl · GitHub.