Very often our tools produce a number of images, which we want to glue together to a movie for getting a nice animation. There are many ways to do this and several webpages describing how to do it. Here we just describe what works best for the type of movies we have.



We mostly use mencoder for our animations, since it's a command line tool with a lot of features to adjust. Arman Khalatyan wrote a script some years ago to take care of the options for you and use two passes to improve movie quality. I adjusted it slightly to take image format and the frame directory as command line arguments:

if [ $# -ne 3 ]
   echo "Please provide file extension, file basename pattern (no extension) and movie name (no extension)."
   echo "Example: "
   echo "   bash png \"frames/image0[0-9]*\" movie1"

rm -f divx2pass.log


# no. of frames per second

mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vpass=1:$opt -mf type=${imgext}:fps=$fps -nosound -o /dev/null mf://$imgmask
mencoder -ovc lavc -lavcopts vcodec=msmpeg4v2:vpass=2:$opt -mf type=${imgext}:fps=$fps -nosound -o $movie mf://$imgmask

Download the script:

This creates a high quality avi-movie file, which can be easily converted to e.g. mp4 using avconv (see Movie conversions). If you need to improve the quality, try increasing the bitrate. However, this will also increase the file size. Consequently, the file size can be reduced by setting the bitrate to a smaller rate, increasing the vqscale quality parameter or adjusting a number of other options. Please consult the MPlayer/Mencoder documentation or its manpage for details.