Page 1 of 1

Writing Gif takes huge time.

Posted: 2013-10-25T12:19:03-07:00
by gegupta

We are trying to convert gif to a gif but bigger images just take huge time(~10-12 sec to write to shared mem). I wanted to confirm if it normal. We have a timeout of 10sec aroud resize for ourc lients but we have fallen into situation where even 10 sec is not enough. Is there any benchmarking done over gif images which I can refer in order to deefinea proper timeout value?

Here is some information:
Writing to /dev/shm is taking as much as 11 sec :

ImageMagick version :
Version: ImageMagick 6.8.6-6 2013-07-23 Q16

Code for timer and sequence of operations :
1) Resize

Code: Select all

Image image_;
image_.resize( boost::lexical_cast<string>(context.getTargetWidth())+"x"+ boost::lexical_cast<string>(context.getTargetHeight()));
2) Apply watermark

Code: Select all

image_.annotate(sn, SouthWestGravity);
3)Apply sharpening

Code: Select all

4) Write to shared memory (/dev/shm)

Code: Select all

 gettimeofday(&tim1, NULL);
               double tWriteStart=tim1.tv_sec+(tim1.tv_usec/1000000.0);
               gettimeofday(&tim1, NULL);
               double tWriteEnd=tim1.tv_sec+(tim1.tv_usec/1000000.0);
               float tWriteFile = (tWriteEnd - tWriteStart)*1000;

               std::ostringstream totalTime;
               totalTime <<"WriteFile," << boost::lexical_cast<std::string>(tWriteFile);
Is the above normal for Gif conversions and writes. I have seen taking it more time through command line too. Is there any optimizations which we can use?

Let me know if I need to provide you with images. Typical image would be somewhere around 1MB and output resized image to say 800pixels is around ~450kb.


Re: Writing Gif takes huge time.

Posted: 2013-10-25T13:38:26-07:00
by fmw42
On my Mac mini dual-core running only one thread in IM, I have a 4.1 MB image of size 3264x2448

time convert P1050001.JPG -colors 256 P1050001.gif

real 0m7.565s
user 0m7.350s
sys 0m0.156s

But adding -treedepth 4 cuts in about half

time convert P1050001.JPG -treedepth 4 -colors 256 P1050001.gif

real 0m4.610s
user 0m4.228s
sys 0m0.173s

Re: Writing Gif takes huge time.

Posted: 2013-10-25T13:55:28-07:00
by gegupta

Can you try convert/resize just gif image to a gif?


Re: Writing Gif takes huge time.

Posted: 2013-10-25T14:28:33-07:00
by fmw42
convert P1050001.JPG P1050001.gif

time convert P1050001.gif -resize 800x800 test.gif

real 0m1.797s
user 0m1.658s
sys 0m0.119s

Re: Writing Gif takes huge time.

Posted: 2013-10-25T15:44:13-07:00
by gegupta

Thanks for your help!
Can you try this: which is GIF already to start with.
Appreciate it!


Re: Writing Gif takes huge time.

Posted: 2013-10-25T15:57:52-07:00
by glennrp
You could try -sample WxH instead of -resize WxH, to avoid creating a lot of new colors that
have to be merged again while writing the GIF.

Re: Writing Gif takes huge time.

Posted: 2013-10-25T16:09:02-07:00
by fmw42
time convert Big2.GIF -resize 800x800 Big2_a.gif

real 0m4.622s
user 0m4.567s
sys 0m0.047s

time convert Big2.GIF -sample 800x800 Big2_b.gif

real 0m0.122s
user 0m0.081s
sys 0m0.031s

time convert Big2.GIF -filter point -resize 800x800 Big2_c.gif

real 0m0.196s
user 0m0.143s
sys 0m0.040s

Glenn is right, it save time resizing, but also avoids creating new colors that have to be re-quantized.

Re: Writing Gif takes huge time.

Posted: 2013-10-28T11:03:22-07:00
by gegupta
Appreciate your help! That was helpful in debugging the problem!