Search code examples
imagemagickimagemagick-convert

How to alter delay in a gif, without altering its speed


For stupid timing reasons, I need a gif that has delay 6. Alas, my material is delay 20.

What I effectively need is to drop delay to 6, and at the same time multiply every frame three or four times. I don't mind the timing being a little off.

This seems like a simple enough problem, but utterly ungoogelable.


Solution

  • You can do it like this:

    #!/bin/bash
    
    # Split animation into constituent frames, saving as "frame-nnn.gif"
    convert animated.gif -coalesce frame-%03d.gif
    
    # Make array of all framenames
    frames=( frame-*gif )
    
    # Triplicate array elements
    for ((i=0;i<${#frames[@]};i++)); do newframes+="${frames[i]} ${frames[i]} ${frames[i]} "; done
    
    # DEBUG echo ${newframes[@]}
    
    # Rebuild animation with new speed
    convert -delay 10 ${newframes[@]} new.gif
    
    # Clean up
    rm frame-*.gif 2> /dev/null
    

    My script assumes your original is called animated.gif and the result will be called new.gif. Obviously you can change the delays and number of duplicates as you wish, the values I have chosen are illustrative.