Making a movie from images
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.
mencoder
Website: https://mplayerhq.hu
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 ]
then
echo "Please provide file extension, file basename pattern (no extension) and movie name (no extension)."
echo "Example: "
echo " bash make_movie.sh png \"frames/image0[0-9]*\" movie1"
exit
fi
rm -f divx2pass.log
opt="vqscale=1.5:vbitrate=2160000:mbd=2:keyint=132:vqblur=1.0:cmp=2:subcmp=2:dia=2:mv0:last_pred=3"
imgext="$1"
imgmask="$2.$imgext"
movie="$3.avi"
# no. of frames per second
fps=24
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: make_movie.sh
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.