How to create animated GIF from set of images

To create a GIF animation from a set of images following command can be used:

ffmpeg -f image2 -i image_%004d.tif  -filter_complex "[0]trim=start_frame=1:end_frame=39,setpts=PTS-STARTPTS,reverse[r];[0][r]concat=n=2:v=1:a=0,fps=10,scale=720:-1" output.gif

This command assumes that there are 40 images in the directory named: image_0000.tif, image_0001.tif …, image_0039.tif (trim filter allows to remove duplicated first and last frame).

The animation will be going back and forth thanks to the reverse and concat filters.

GIF animation speed is controlled by fps filter and rezising is achieved thanks to the scale filter.