Page 1 of 1

Out of memory on iOS

Posted: 2014-06-12T18:21:26-07:00
by jheid
Hi.

When I generate a huge animated GIF on iOS I get an out of memory error while adding the frames:

Code: Select all

MagickWand* mw = NewMagickWand ();
MagickSetFormat (mw, "gif");
NSString* item;
for (item in contents) {
       MagickWand* localWand = NewMagickWand ();
       NSData* dataObj = UIImagePNGRepresentation ([UIImage imageWithContentsOfFile:[screenshotsPath stringByAppendingPathComponent:item]]);
       MagickReadImageBlob (localWand, [dataObj bytes], [dataObj length]);
       MagickSetImageDelay (localWand, 10);
       MagickAddImage (mw, localWand);
       DestroyMagickWand (localWand);
       }
Is there any way to get around this error?

Cheers

Re: Out of memory on iOS

Posted: 2014-06-13T06:17:35-07:00
by magick
ImageMagick allows you to set memory resource limits, see http://www.imagemagick.org/script/resources.php. If you set a memory resource limit, once that limit is reached, ImageMagick caches the pixels to disk to conserve memory. If memory and your disk both point to the same flash drive than you would be forced to use web services to get around this resource constraint. Also check to see if you're using Q16 or Q8 of ImageMagick. The Q8 version only uses 8-bits per pixel, whereas the Q16 version using 16-bits per pixel (suggesting double the memory resource requirements).

Re: Out of memory on iOS

Posted: 2014-06-13T08:25:01-07:00
by jheid
Thanks.

I added

Code: Select all

MagickSetResourceLimit (MemoryResource, 500000000);
so there's no out of memory problem any more but combining those images last 41 minutes where another implementation for animated gifs (GifLib) takes about 11 minutes on an iPad Air.

Code: Select all

MagickQuantizeImages (mw, 256, RGBColorspace, 4, MagickFalse, MagickFalse);
MagickWriteImages (mw, [videoPath UTF8String], MagickTrue);
Any idea how to speed it up? It combines 100 1536x2048 pixel images. And yes, that's intended.

Re: Out of memory on iOS

Posted: 2014-06-13T09:24:41-07:00
by magick
Write the output to PNG. How long does that take? ImageMagick emphasizes the quality of the results rather than wall-clock time. The color reduction algorithm returns superior results but is known to be slow. Try enabling dithering. Does that help? You could also create a single colormap image and map the image sequence to that single colormap with MagickMapImage() and that may run much faster.