Page 1 of 1

how to speed up writing animated gif

Posted: 2007-11-26T15:19:03-07:00
by jgcochran
Hi, I am using Magick++ to write out an animated gif and it seems to be taking a long time. I was wondering if there was any way to speed up the process. Using the example code below, I'm writing 39 frames of size 256 x 512 as an animated gif and it takes 21 seconds on a fast computer. When using the same code to write it out as a 'movie.miff' file instead of an animated gif it takes just 0.5 seconds but is much larger and in a format that I can't use. Thanks


// Already filled out list with 39 frames which are 256 x 512
list<Image> dimgs;
const int sz = dimgs.size();

// Set the frame rate.
double framesPerSecond = 2.0;
const int animationDelay = int(::rint(1.0 / framesPerSecond * 100));
for (list<Image>::iterator dd = dimgs.begin();
dd != dimgs.end(); dd++)
{
dd->animationDelay(animationDelay);
dd->matte(false);
}

// Write out animated gif.
Magick::writeImages(dimgs.begin(), dimgs.end(),"movie.gif");

Re: how to speed up writing animated gif

Posted: 2007-11-26T19:26:24-07:00
by anthony
The slowness in in IM doing color quantization on the modified images, for each and every frame. That is your annotation is causing the image to contain more colors than a GIF frame can handle.

The best solution for this is to use a bitmap font of some type rather than an anti-aliased true-type font.

The IM font system is supposed to be able to handle the old X windows bitmap font libraries (with or without an X windows server) but as of yet I have not been able to get this to work successfully. This is one reason why I have not discussed font selection in IM examples properly.

Re: how to speed up writing animated gif

Posted: 2007-11-27T19:45:24-07:00
by jgcochran
Thanks for your response. I am not using any annotations or fonts in the frames. In fact, before writing out the images, I have scaled them so that each frame contains integer pixel values between 0 and 255.

It makes sense to me that the slowness is probably in the color quantization of each frame. Is there any way to speed this process up somehow? For instance, is there a way to not perform the color quantization on each frame, maybe just on 1 frame? My priorities are primarily speed, like speeding it up from taking 21 seconds to about 1 to 2 seconds. If that sacrifices other things like compression, that's fine with me.

Could you show me how to do this with a couple snippets of Magick++ C code. I'm not using scripting. Thanks

Re: how to speed up writing animated gif

Posted: 2007-11-27T21:57:27-07:00
by anthony
jgcochran wrote:Thanks for your response. I am not using any annotations or fonts in the frames. In fact, before writing out the images, I have scaled them so that each frame contains integer pixel values between 0 and 255.
Not certian what you mean by scale them. IM does not let you do that! It is the number of colors that matter, not the size of the image or the number of color increments you are using,
It makes sense to me that the slowness is probably in the color quantization of each frame. Is there any way to speed this process up somehow? For instance, is there a way to not perform the color quantization on each frame, maybe just on 1 frame? My priorities are primarily speed, like speeding it up from taking 21 seconds to about 1 to 2 seconds. If that sacrifices other things like compression, that's fine with me.
IM automatically goes though a quantization/dither cycle if the number of colors, is more than 256 (including transparency). If number of colors is less than that it should only generate the color table, and not quantize/dither the image. You can turn off dither using +dither, though if you have too many colors that may produce a horrible image.
Could you show me how to do this with a couple snippets of Magick++ C code. I'm not using scripting. Thanks
Sorry I don't use Magcik++, I occasionally use PerlMagick, and do often do modifications to the C Magick Core libraries to make improvements (currently working on resize filters and Distortion resampling) but never on Magick++. Sorry.