Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect an animated GIF's ticks per second?

I'm looking for a way to detect the (average) frame rate of an animated GIF using Linux. PHP's Imagick class seems to provide this functionality but I rather avoid installing a ton of libraries to get it to work.

http://www.php.net/manual/en/function.imagick-getimagetickspersecond.php

Is there a simple way to do this?

like image 512
Elbert Alias Avatar asked Aug 27 '10 22:08

Elbert Alias


People also ask

How do I know how many frames per second is a GIF?

A GIF file doesn't contain an FPS value, rather each frame contains a duration. Each frame contains a header. Hex Byte Number 324 contains the frame duration in 100ths of a second, for example 09 00 would be 0.09 seconds.

Can a GIF be 30 fps?

Adjusting the Timeline Frame Rate will change how many frames per second (fps) your animated GIF file will go by. When making an animated GIF in Photoshop, Photoshop is set to 30 fps by default. 30 fps may be good to work, but when creating an animated gif in photoshop you may need to adjust.

Can GIFs have 60 fps?

So exactly 60 FPS is not possible. Note that this extension was meant for a handful of frames with a delay on the order of seconds (maximum delay is about 600 seconds), so 1/100 seconds resolution was ample.


2 Answers

I think ImageMagick really is your best bet.

This is what a identify filename.gif on an animated GIF looks like:

gif.gif[1] GIF 350x350 350x350+0+0 8-bit PseudoClass 256c 145KB 0.000u 0:00.003
gif.gif[2] GIF 350x350 350x350+0+0 8-bit PseudoClass 256c 145KB 0.000u 0:00.006
gif.gif[3] GIF 350x350 350x350+0+0 8-bit PseudoClass 256c 145KB 0.000u 0:00.010

this doesn't give you the frame rate - which is good, because animated GIFs don't have a global frame rate, they have an individual one between frames.

like image 149
Pekka Avatar answered Sep 24 '22 08:09

Pekka


You can customize the info format of what ImageMagick's identify should display to you:

identify \
      -format "%T ticks:  %f: Frame[%s]  %m %wx%h %P%O %r %z-bit\n" \
       anim.gif

That should do the trick.

Example output:

 50 ticks:  anim.gif: Frame[0]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[1]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[2]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[3]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[4]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 50 ticks:  anim.gif: Frame[5]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[6]  GIF 1x1 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[7]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[8]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[9]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
 10 ticks:  anim.gif: Frame[10]  GIF 128x128 128x128+0+0 PseudoClass sRGB Matte 8-bit
like image 25
Kurt Pfeifle Avatar answered Sep 22 '22 08:09

Kurt Pfeifle