How to speed up animated GIF

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
fibonacci1101
Posts: 4
Joined: 2012-02-22T07:22:12-07:00
Authentication code: 8675308

How to speed up animated GIF

Post by fibonacci1101 »

Hello everyone ;)

I know the topic of my post seems familiar and there is a lot topics like this but none of them could help me solve my problem.
So, I'm converting a group of images into animated GIF, that I've extracted from video file, using this command:
convert pics-*.png -resize 500x281 animated.gif
And in the result I get animated GIF that is runing with the same speed as video file is. I suppose that this command is using by default -delay 0.
But I want to make my GIF even faster. Is there a way to do this using ImageMagick?
The only way I dicovered was to firstly convert the video file using ffmpeg and this command:
ffmpeg -i video.mp4 -f yuv4mpegpipe - | yuvfps -s 100:1 -r 100:1 | ffmpeg -f yuv4mpegpipe -i - -r 25 -y output.mp4
which is speeding up the video file 4x, then using this command:
ffmpeg -i output.mp4 -f image2 pics-%04d.png
to extract all the frmaes from speeded up output file and then convert them to GIF using command "convert"
Is there any faster and easier way to do this?
What I want to do is to do this without speeding up the video file, just extract frames from original video file and speed it up using "convert" command.
Something like this: convert pics-*.png -resize 500x281 "-here some command speeding GIF up" animated.gif
Is there any way to achieve it? Please, help me solve my problem ;)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to speed up animated GIF

Post by fmw42 »

I believe that gif animations may have some minimum delay. But even if not, the viewer usually imposes restrictions of its own. Different viewers will give different speeds even when the -delay from IM is 0. However, I will defer to those more experienced with animations than me.
fibonacci1101
Posts: 4
Joined: 2012-02-22T07:22:12-07:00
Authentication code: 8675308

Re: How to speed up animated GIF

Post by fibonacci1101 »

It's not about changing delay because I believe that delay 0 is the lowest and gif cannot animate any faster. It's more about morphing/joining frames and by it reducing the numer of frames but maintaining the fluency/smoothness of the animation.Is there any command that can do it? Any help?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to speed up animated GIF

Post by fmw42 »

fibonacci1101 wrote:It's not about changing delay because I believe that delay 0 is the lowest and gif cannot animate any faster. It's more about morphing/joining frames and by it reducing the numer of frames but maintaining the fluency/smoothness of the animation.Is there any command that can do it? Any help?

Still not sure what you mean, but IM has -morph. See http://www.imagemagick.org/script/comma ... .php#morph and http://www.imagemagick.org/Usage/anim_mods/#morph
fibonacci1101
Posts: 4
Joined: 2012-02-22T07:22:12-07:00
Authentication code: 8675308

Re: How to speed up animated GIF

Post by fibonacci1101 »

I mean morphing like joining few frames into new one. So if originally GIF is consisted of, let's say, 60 frames than after converting it with IM it will be 40 frames for example. I don't know how to explain it better, maybe I will prepare some GIFs and show them to you later.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to speed up animated GIF

Post by fmw42 »

fibonacci1101
Posts: 4
Joined: 2012-02-22T07:22:12-07:00
Authentication code: 8675308

Re: How to speed up animated GIF

Post by fibonacci1101 »

Ok, I came up with this idea. While extracting frames from video I'm using this command:

ffmpeg -i input.mp4 -f yuv4mpegpipe - | yuvfps -s 75:1 -r 75:1 | ffmpeg -f yuv4mpegpipe -i - -r 25 -y -f image2 output-%04d.png

So it's like speeding up video first and then extracting it frames, but without genereting new video file. In result I'm getting aproximetly every third frame from the input video file. And then I can make a gif from extracted frames using "convert".

But the "-delete" formula seems to work too. It can be used when the GIF is already made so you can remove every second or every third frame from it to make it look faster.

If anyone will come up with better formula please let me know ;)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to speed up animated GIF

Post by anthony »

fibonacci1101 wrote:I mean morphing like joining few frames into new one. So if originally GIF is consisted of, let's say, 60 frames than after converting it with IM it will be 40 frames for example. I don't know how to explain it better, maybe I will prepare some GIFs and show them to you later.
Removing frames is a matter of coalesing the animation, and removing say every second frame. Their is no simple automated way to do this in ImageMagick, at least not at this time. A shell wrapper, or image pipeline such as described in the 'video' solution above, could do it. Note I doubt even IMv7 improved CLI could do this directly in IM itself.


Note the cartoon artists also had similar problems, making a character move quickly from on place to another when you can't use enough frames to show that movement. Their solution was one intermediate 'blurred' frame.
For example... This is only 4 frames!
Image
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply