Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the length of a .gif animation in milliseconds

Is there an easy way to figure out approximately how long a .gif image takes to play one time in Javascript?

like image 885
j00b Avatar asked Mar 21 '12 20:03

j00b


People also ask

How long is a GIF animation?

Uploads are limited to 15 seconds, although we recommend no more than 6 seconds. Uploads are limited to 100MB, although we recommend 8MB or less. Source video resolution should be 720p max, but we recommend you keep it at 480p. Keep in mind media will appear mostly on small screens or smaller messaging windows.

How many seconds per frame is a GIF?

Standard GIFs run between 15 and 24 frames per second. Overall, the smaller your GIF file size, the lower the quality will be. When creating GIFs for the web, it is all about finding the smallest file size possible without sacrificing too much quality.

How can I tell the frame rate of a GIF?

The frame rate can be calculated by counting how many delays fit in 1 second of animation. For example, if the delay is 100ms, then the frame rate is 10fps (because 10×100ms = 1 second), or if the delay is 40ms, then the frame rate is 25fps (because 25×40ms = 1 second).

What size are animated GIFs?

Average size of a GIF960×540 for our wide format is ideal. Second, you can reduce the # of frames per second – something like 5 or 6 per second is fine.


2 Answers

The identify command from ImageMagick can give this information:

$ identify -verbose file.gif | grep 'Elapsed time'

  Elapsed time: 0:01.080
  Elapsed time: 0:01.150
  Elapsed time: 0:01.230

...

  Elapsed time: 0:04.250
  Elapsed time: 0:04.330
  Elapsed time: 0:04.399
  Elapsed time: 0:04.480

The last line printed should be the total length of the animation.

like image 65
Martin Vilcans Avatar answered Sep 20 '22 12:09

Martin Vilcans


The accepted answer doesn't give the exact result. Elapsed time is like a real world clock while ImageMagick runs the animation. What you want is the Delay field for each frame and sum them up.

$ identify -verbose fail.gif  | grep Delay

Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 15x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 10x100
Delay: 33x100
Delay: 10x100
Delay: 10x100
Delay: 10x100

Where 33x100 is a delay of 330ms.

Edited by Mark Setchell

You can actually extract the delay parameter somewhat more surgically (than by using grep) with the %T escape:

enter image description here

identify -format "%T\n" animation.gif 

8
8
8
8
8
8
8
8
8
8
11
11
11
11
11
11
11
26

And get the total with awk like this:

identify -format "%T\n" anomation.gif | awk '{t+=$0} END{print t " centiseconds"}'
183 centiseconds
like image 34
Prinzhorn Avatar answered Sep 21 '22 12:09

Prinzhorn