The following procedure prevents ImageMagick from consuming excessive system resources. It has been tested with ImageMagick 6.8.9-9 on Ubuntu 15.04. To illustrate the procedure, I use the example of converting a video to an animated GIF.
Set up ImageMagick such that it doesn't consume excessive system resources:
export MAGICK_MEMORY_LIMIT=1024
export MAGICK_MAP_LIMIT=1024
export MAGICK_AREA_LIMIT=4096
export MAGICK_FILES_LIMIT=1024
export MAGICK_THREAD_LIMIT=1
export MAGICK_TMPDIR=/home/user/tmp
The environment variable MAGICK_THREAD_LIMIT
limits the number of threads used by ImageMagick (when it is built with OpenMP enabled). The environment variable MAGICK_TMPDIR
is a path to a directory at which ImageMagick can store temporary files. It is particularly useful for frame images of relatively large size because it avoids excessive RAM memory usage.
Prepare the input filename, the output filename and the directory at which frame images are to be stored.
filename1=2015-11-09T1300Z.mp4
filename2=2015-11-09T1300Z.gif
directoryName1="tmp_images"
Convert the video to a number of frame images (setting the time limits as appropriate; in this example, from 0 seconds to 30 seconds).
mplayer -ao null -ss 0:00:00 -endpos 30 "${filename1}" -vo jpeg:outdir="${directoryName1}":quality=100
If reasonable for output file size constraints, reduce the size of the video frames (in this example, by 50%).
mogrify -resize 50% "${directoryName1}"/*.jpg
Use ImageMagick to convert the frame images to an animated GIF.
convert -delay 5 -loop 0 -layers optimize -limit memory 64 "${directoryName1}"/*.jpg "${filename2}"