1

Is there a way to duplicate frames in an animated gif by a given number? For example, the below gif has four frames.

enter image description here

I want each frame to be repeated three times, in effect sowing it down, as in the example below.

enter image description here

Is there a way to do this using imagemagick, gifsicle or some other open source software that runs on linux desktops in the command line?

(I'm aware that you can set a delay/duration for each frame but in this instance I need to duplicate frames instead of changing their durations)

1
  • 1
    Duplicating frames is an inefficient way to slow down a gif, because it will result in a larger file size in comparison to simply increasing the frame delay. Why do you need to do that?
    – Billy Kerr
    May 15, 2020 at 14:28

1 Answer 1

2

Reposting (with permission) mathr's answer from Mastodon

Save the code below to script.sh

#!/bin/bash

# 1. get input frame count (note two spaces after the "\")
count=$(gifsicle --info < input.gif | grep "<stdin>" | cut -d\  -f 3)

# 2. define how many times to repeat frames
repeats=5

# 3. construct new frame list
frames=$(for i in $(seq 0 $((count - 1)))
    do 
        for j in $(seq $((repeats)))
            do echo "#$i"
        done
    done
)

# 4. use gifsicle to duplicate frames (note no quotes around $frames)

gifsicle < input.gif $frames > output.gif

On the original gif it produces the following output, where each frame has been repeated 5 times.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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