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 inputfile.ps 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 yyyy_ddd.ps, where, yyyy is the year, and ddd is the day of the year, such as 2010_1.ps, 2010_2.ps and so on. So you can use the for loop and convert as follows:
for ((i=1;i<366;i++))
do
echo day: $i
convert -rotate "-90" 2010_$i.ps 2010_$i.jpg
done
If you have numbered the files and padding it with zeros, let’s say 2010_001.ps, 2010_002.ps and so on, you can use the following code snippet
for ((i=1;i<366;i++))
do
echo day: $i
convert -rotate "-90" 2010_`printf "%03d" $i`.ps 2010_`printf "%03d" $i`.jpg
done
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.