How to make gif which goes backwards and forwards on a loop?

13,486

Solution 1

The easiest way would be to do it with this online tool. Simply upload the GIF and mark "run to the end and reverse back to the start" checkbox.

I haven't seen any Linux tool with such feature built in, but if you don't want to use online tools or the file is too large, you could split the GIF using gifsicle, copy and rename the frames or just make a list of filenames in ascending and descending order and join them back together, again - using gifsicle.

Something like this could do the trick:

gifsicle --unoptimize --explode original.gif && 
find . -iname "*\.gif\.*" | sort > frame_list.txt && 
find . -iname "*\.gif\.*" | sort -r >> frame_list.txt && 
cat frame_list.txt | xargs gifsicle > reversed.gif

(In case you get broken/flickering gif or some gifsicle error, you may need to remove optimizations with imagemagick before splitting it: convert original.gif -coalesce unoptimized.gif)


For the mp4 to gif conversion step, there are many different options online and offline, but I have found this to produce the best results: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

Disassembling and reassembling a GIF after it's made shouldn't affect the quality at all, the mp4 to gif conversion step will determine the quality.

Solution 2

To create a "forward + backward" GIF, under Ubuntu / Linux let's use the wonderfull software called gifsicle.
The command is simple:

gifsicle --unoptimize original.gif original.gif "#-1-0" > reversed.gif

It simply concatenate the same gif two times, one forward, one backward. (note, the unoptimize is usefull when gifs are optimised and can lead to glitch when play backward)

Share:
13,486

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I have an mp4 clip which I would like to turn into a smooth looking gif which would replay backwards at the same speed and quality as it plays forwards. That is when it would reach the end of the clip, it would play backwards in reverse and then when it comes to the end of the reversed version it would start playing the normal one and it would carry on on a loop so that it would look smooth with no jumping.

    I am running Ubuntu GNOME 16.10 with GNOME 3.22, are there any video editors or other applications which I could use to do these? And if so, which ones and how? Or perhaps a script to reverse all the frames to create a new one and then merge them into a gif? Just as long as the speed and quality is fine and the same and no jumpiness then I don't really mind how it's done.

  • David Foerster
    David Foerster about 7 years
    Welcome to Ask Ubuntu! I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
  • Admin
    Admin about 7 years
    It would be better to include all necessary information in the answer rather than just posting a link to an article which may be moved, lost or deleted. Copying and pasting is fine as long as you quote the source.