4

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.

M.R.
  • 31,425
  • 8
  • 90
  • 281
  • 2
    I believe the only solution to this is the ugly brute force way: give it a bunch of duplicate copies of the last frame. – george2079 May 24 '16 at 21:06
  • 1
    @george2079 has it right, there's no delay-by-frame options. – ciao May 24 '16 at 21:13
  • 1
    having said that, @Karsten7 's answer does work. I don't know how universally that will be supported by different viewers however. – george2079 May 24 '16 at 21:32
  • 2
    @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. – Jens May 24 '16 at 23:30

1 Answers1

10

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.
Karsten7
  • 27,448
  • 5
  • 73
  • 134
  • "All too easy" - I forgot I was using a list! – M.R. May 24 '16 at 21:34
  • 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? – M.R. May 25 '16 at 15:03
  • @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. – Karsten7 May 25 '16 at 17:23
  • @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). – Karsten7 May 25 '16 at 17:47
  • Nice! Also seems the minimum display duration is 0.015 second, can you confirm? – M.R. May 26 '16 at 03:30
  • @M.R. In the GIF file format specifications it is called delay time. Its minimum is 0 and its smallest nonzero number is one hundredths of a second, which is also the minimum increment. But browsers will use a fixed value that is specific to the browser if the delay is under a certain threshold (that is browser specific, again). – Karsten7 May 26 '16 at 07:28