Friday, May 29, 2009

Create animations with ImageMagick

A frequent task in post-processing scientific numerical simulations consists of creating a movie of simulation runs.

If your simulation codes saves on files graphical snapshots (plots, images, etc. ...) regarding your system, you can create a corresponding movie at the end of the simulation run.

A simple way to create a movie is to put together in a sequence the single snapshots.

ImageMagick
is a software suite providing lots of commands for image processing.
Using its command convert you can also stack together in a sequence your simulation snapshots.

Simple example of its use:

convert -adjoin -delay X file_snapshot1 file_snapshot2 ... file_snapshotN file_movie.format

While convert is routinely used for converting an image file from one format into another, it can be used also for stacking together image files into a movie file passing to it the option -adjoin.

-delay X indicates the (real) time delay (X) between one snapshot and the following one. The delay is expressed in a default unit: one 100th of second. This default value can be changed.

After delay put the list of image files being your snapshots. If the files are numbered and ordered incrementally, you can just use wildcards (''*'' character in Linux/Unix) for indicating the changing index. Finally you have to indicate the name of the movie file followed by the format extension. ImageMagick will use the right encoder according to the format extension it finds in the movie filename.