Writing Gif takes huge time.

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
gegupta
Posts: 30
Joined: 2010-12-03T12:14:09-07:00
Authentication code: 8675308

Writing Gif takes huge time.

Post by gegupta »

Hello,

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 :
TotalTimeResize:=LoadLib,0,,readFile,0,resize,93.7402267,Unsharp,0,WriteFile,11289.8281

ImageMagick version :
Version: ImageMagick 6.8.6-6 2013-07-23 Q16 http://www.imagemagick.org

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_.composite(imageCameraIcon,Magick::SouthEastGravity,Magick::ModulateCompositeOp);
image_.annotate(sn, SouthWestGravity);
3)Apply sharpening

Code: Select all

image_.unsharpmask(0.8,0.5,1.2,0.05);
4) Write to shared memory (/dev/shm)

Code: Select all

 gettimeofday(&tim1, NULL);
               double tWriteStart=tim1.tv_sec+(tim1.tv_usec/1000000.0);
               image_.write(fileName_.c_str());
               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.

Thanks
G
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Writing Gif takes huge time.

Post by fmw42 »

On my Mac mini dual-core running only one thread in IM 6.8.7.2, 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
gegupta
Posts: 30
Joined: 2010-12-03T12:14:09-07:00
Authentication code: 8675308

Re: Writing Gif takes huge time.

Post by gegupta »

Hi,

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

Thanks
Geetanjali
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Writing Gif takes huge time.

Post by fmw42 »

convert P1050001.JPG P1050001.gif

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

real 0m1.797s
user 0m1.658s
sys 0m0.119s
gegupta
Posts: 30
Joined: 2010-12-03T12:14:09-07:00
Authentication code: 8675308

Re: Writing Gif takes huge time.

Post by gegupta »

Hi

Thanks for your help!
Can you try this:https://ebay.app.box.com/s/vukrtbag57gstcxfn634 which is GIF already to start with.
Appreciate it!

Thanks
G
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Writing Gif takes huge time.

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Writing Gif takes huge time.

Post 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.
gegupta
Posts: 30
Joined: 2010-12-03T12:14:09-07:00
Authentication code: 8675308

Re: Writing Gif takes huge time.

Post by gegupta »

Appreciate your help! That was helpful in debugging the problem!
Post Reply