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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With