Animating Graphic Files

If you are doing any numerical simulation or modeling, it happens quite often that you want to show a series of your solution snapshots one after each other to make an animation on how the solution is evolving. There are different software available to do this, but we are going to limit ourselves to the freely available one on Linux and MAC.

Even if you are not animating graphics, but you want to perform a certain task on multiple graphic files or change their format this post gonna be helpful.

Using ImageMagick:

I had another post about ImageMagick. You can install ImageMagick on Ubuntu as follows:

sudo apt-get install imagemagick

or use the “port” command if you are on Mac. ImageMagick provides you with a command prompt command “convert” that you can perform several operation on graphic files. For example, if you want to convert a PostScript file into a JPEG file and rotate it by 90 degree counterclockwise you must issue:

convert -rotate -90 outputfile.jpg

So, now let’s say you have one file per day for a year, let’s say you have created a map of air temperature at 10:00am and you have named them, where, yyyy is the year, and ddd is the day of the year, such as, and so on. So you can use the for loop and convert as follows:

for ((i=1;i<366;i++))
echo day: $i
convert -rotate "-90" 2010_$ 2010_$i.jpg

If you have numbered the files and padding it with zeros, let’s say, and so on, you can use the following code snippet

for ((i=1;i<366;i++))
echo day: $i
convert -rotate "-90" 2010_`printf "%03d" $i`.ps 2010_`printf "%03d" $i`.jpg

Using ffmpeg:

You can install this package using apt-get as follows:

sudo apt-get install ffmpeg

or use the equivalent port command on Mac. Now if you want to animate your jpg files you can issue:

ffmpeg -r fps -i /InputFiles/Prefix%3d.jpg  Output.avi

where fps is the number of frame per seconds.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s