4
$\begingroup$

I'd like for there to be a pause during the final frame in my animation, before it loops.

Here's some tweekable starter code:

frames = Import["ExampleData/cellularautomaton.gif"];

Export["~/cellularautomaton.gif", frames, "Interlaced" -> True, 
 "DisplayDurations" -> Table[0.1, Length[frames]], 
 "AnimationRepetitions" -> \[Infinity]]

I looked at the docs for .GIF, nothing there on this. Also, I thought of padding the list with repetitions of the last frame, but that is a waste of space, and the GIF mime type supports this.

$\endgroup$
  • 2
    $\begingroup$ I believe the only solution to this is the ugly brute force way: give it a bunch of duplicate copies of the last frame. $\endgroup$ – george2079 May 24 '16 at 21:06
  • 1
    $\begingroup$ @george2079 has it right, there's no delay-by-frame options. $\endgroup$ – ciao May 24 '16 at 21:13
  • 1
    $\begingroup$ having said that, @Karsten7 's answer does work. I don't know how universally that will be supported by different viewers however. $\endgroup$ – george2079 May 24 '16 at 21:32
  • 2
    $\begingroup$ @george2079 Providing a list as DisplayDuration has worked pretty much since forever. See, e.g., this old post. So there definitely is a delay-by frame option. $\endgroup$ – Jens May 24 '16 at 23:30
10
$\begingroup$

You can simply increase the display duration for the last frame.

Export["test.GIF", frames, "Interlaced" -> True,   
 "DisplayDurations" -> ReplacePart[Table[0.1, Length[frames]], -1 -> 1.0], 
 "AnimationRepetitions" -> ∞]

Citing the GIF documentation:

  • "DisplayDurations"->{d1, d2, ...} specifies the display durations for each frame in an animated GIF. If the list of display durations is shorter than the number of frames, the sequence is repeated as necessary.
  • With the default setting "DisplayDurations"-> Automatic, the display time will vary on different viewer applications.
$\endgroup$
  • $\begingroup$ "All too easy" - I forgot I was using a list! $\endgroup$ – M.R. May 24 '16 at 21:34
  • $\begingroup$ This could be a separate questions, but what about changing the "AnimationDirection" to "ForwardBackward" in the gif? Would I have to double the number of frames or is there an undocumented option? $\endgroup$ – M.R. May 25 '16 at 15:03
  • $\begingroup$ @M.R. AFAIK there is nothing like an "AnimationDirection" for GIFs. It's not part of the file specification and it's not how GIFs work. If you want to create a "ForwardBackward" GIF, you'll have to create a complete "ForwardBackward" list of frames as one loop. If you do so just using Mathematica the file size will probably be twice. However, other tools (e.g. GIMP) can do a much better job optimizing a GIF (for example using combine frames instead of replace frames), which results in much smaller file sizes. $\endgroup$ – Karsten 7. May 25 '16 at 17:23
  • $\begingroup$ @M.R. This GIF is Mathematica exported forward (2 KB), this GIF is Mathematica exported forward and backward (4 KB), and this GIF is the forward and backward GIF optimized with GIMP (1 KB). $\endgroup$ – Karsten 7. May 25 '16 at 17:47
  • $\begingroup$ Nice! Also seems the minimum display duration is 0.015 second, can you confirm? $\endgroup$ – M.R. May 26 '16 at 3:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.