Page 1 of 1
[c++] how to count frames in an animated gif
Posted: 2012-04-16T21:03:35-07:00
by qyp
Hi,
I used readImages to read the frames into a container and got the frame count by querying the container's size.
However, this method consumes a lot of memory, especially when the frame count is large.
Is there any better way?
Thanks
Re: [c++] how to count frames in an animated gif
Posted: 2012-04-16T21:28:39-07:00
by anthony
Use something more specific to GIF.
Look at giftrans from my software export (I did not write it, though I did make a minor patch)
http://www.ict.griffith.edu.au/anthony/ ... /#giftrans
It should be fast because it does not actually do a lot of processing of the image, just reading.
Re: [c++] how to count frames in an animated gif
Posted: 2012-04-17T01:12:15-07:00
by qyp
Thanks
This information is very helpful
Re: [c++] how to count frames in an animated gif
Posted: 2012-04-17T16:38:12-07:00
by anthony
Note that I am not putting ImageMagick down by suggesting a alternative bit of software.
The IM "identify" command can generate a summary of the images, or even more.
One such application is "gif2anim" which converts a GIF image into a fiel of IM options, that can re-create the GIF animation from seperate frames (whcih it can also create).
http://www.imagemagick.org/Usage/scripts/gif2anim
See Animation Basics, List Information
http://www.imagemagick.org/Usage/anim_basics/#list_info
However programs designed for a specific format will generally beat a general image processor like ImageMagick....
Shells are a tool, and we are its carpenters.
Sometimes we need a hammer and sometimes a screwdriver.
Re: [c++] how to count frames in an animated gif
Posted: 2017-09-28T12:38:26-07:00
by crx
Hello,
Im searching an trying now the whole day, to get an integer with the number of the frames that are in a gif file.
Im using libmagick++ 6 on a Beagleboneblack with Ubuntu 14.
My c++ code reads different pictures and displays it on a huge DIY LED Matrix, with FPGA.
I want to loop the GIFs of coure, so i want to know what to write to the for loop.
Code: Select all
Image image(pfad); //when I know the number of frames, I want to change to the next frame via the path.
//I tryed this (stringofpath[n] - where n is the frame) and it works, but does anyone know a
//better way or is this a legit way?
int delay;
delay=image.animationDelay()*10; // I read in the dokumentation the value here is in 1/100S so
//it is delay*1 mS between two frames - in praxis i saw it is delay*10mS
//... Had anyone seen this too? (cout is 4 - the GIF has 40ms)
PixelPacket *pixels = image.getPixels(0, 0, w, h); //Get the pixels for the matrix
/* a lot of black magic to get the Pixels into the Matrix B) */
Thanks for your help!
crx