[c++] how to count frames in an 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
qyp
Posts: 2
Joined: 2012-04-12T23:20:37-07:00
Authentication code: 8675308

[c++] how to count frames in an animated gif

Post by qyp » 2012-04-16T21:03:35-07:00

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

User avatar
anthony
Posts: 8874
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [c++] how to count frames in an animated gif

Post by anthony » 2012-04-16T21:28:39-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

qyp
Posts: 2
Joined: 2012-04-12T23:20:37-07:00
Authentication code: 8675308

Re: [c++] how to count frames in an animated gif

Post by qyp » 2012-04-17T01:12:15-07:00

Thanks
This information is very helpful

User avatar
anthony
Posts: 8874
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [c++] how to count frames in an animated gif

Post by anthony » 2012-04-17T16:38:12-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

crx
Posts: 1
Joined: 2017-09-28T11:07:58-07:00
Authentication code: 1151

Re: [c++] how to count frames in an animated gif

Post by crx » 2017-09-28T12:38:26-07:00

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

Post Reply