0
votes

I can create an animated gif using the commands below.

ffmpeg -i wrist_0001.png -vf palettegen=16 palette.png

ffmpeg -i wrist_%04d.png -i palette.png -filter_complex "fps=20,scale=720:-1:flags=lanczos[x];[x][1:v]paletteuse" logo.gif

What I'm trying to know how to do is:

  1. Create another animated gif using just the first 20 frames and the animation loops endlessly (no pausing at the end of the animation).
  2. Create another animated gif using just the first 20 frames where the animation plays then pauses at the end for 3 seconds then continues. (endlessly) Example: (play animation - pause 3 seconds - play animation - pause 3 seconds - play animation - pause 3 seconds...)

Note: I'm trying to avoid having to type in wrist_0001.png wrist_0002.png...is there away to do wrist_0001.png to wrist_0020.png?

1

1 Answers

1
votes
  1. Create another animated gif using just the first 20 frames and the animation loops endlessly (no pausing at the end of the animation):

    ffmpeg -framerate 20 -i wrist_%04d.png -filter_complex "scale=720:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=16[p];[s1][p]paletteuse" -frames:v 20 -loop 0 20framesloop.gif
    
    • When using a set of images as the input set the frame rate with the -framerate image demuxer input option. Your original command is defaulting to 25 fps and then using the fps filter to convert to 20 fps meaning frames are being dropped.

    • -loop 0 is the default for the GIF muxer, but I added it to show how it works if you want to change the looping. 0 means infinite loop.

    • This example makes the GIF in one command as shown in How do I convert a video to GIF using ffmpeg, with reasonable quality?

  2. Create another animated gif using just the first 20 frames where the animation plays then pauses at the end for 3 seconds then continues. (endlessly)

    Most efficient method is to re-mux the GIF from the previous step:

    ffmpeg -i 20framesloop.gif -c copy -final_delay 300 -loop 0 3secpause.gif
    

    -final_delay 300 takes a value in centiseconds, so 3 seconds is 300 centiseconds. See ffmpeg -h muxer=gif for more info.