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

gifsoftware-recommendationvideo-editor

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.

Best Answer

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.