# Creating gifs with Makie is much slower than creating mp4s

**URL:** <https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537>\
**Category:** Visualization\
**Tags:** makie, animations, cairomakie\
**Created:** [August 6, 2023, 6:48pm UTC](https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537 "2023-08-06T18:48:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnomotani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnomotani/32/26753_2.png) [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Post date:** [August 6, 2023, 6:48pm UTC](https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537/1 "2023-08-06T18:48:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [August 6, 2023, 7:14pm UTC](https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537/2 "2023-08-06T19:14:12Z")

</div>

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… 😀

---

<div class="post-metadata">

**Author:** ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)\
**Post date:** [August 7, 2023, 2:59am UTC](https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537/3 "2023-08-07T02:59:11Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [August 7, 2023, 8:48am UTC](https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537/4 "2023-08-07T08:48:27Z")

</div>

> 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](https://docs.makie.org/stable/documentation/animation/index.html#file_formats)  
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:

```julia
# 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](https://github.com/JuliaIO/GIFImages.jl/issues/19) ?

---

<div class="post-metadata">

**Author:** ![johnomotani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnomotani/32/26753_2.png) [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Post date:** [August 7, 2023, 11:10am UTC](https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537/5 "2023-08-07T11:10:49Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![johnomotani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnomotani/32/26753_2.png) [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Post date:** [August 8, 2023, 8:50am UTC](https://discourse.julialang.org/t/creating-gifs-with-makie-is-much-slower-than-creating-mp4s/102537/6 "2023-08-08T08:50:06Z")

</div>

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](https://github.com/MakieOrg/Makie.jl/issues/3132).
