Table of Contents

Making an MFM video

If the -p command line switch is given, the mfm simulator will generate .PNG screenshots, one per epoch, written to the vid/ subdirectory of the main simulation directory (which is usually something like /tmp/DATEBASEDNUMBERS, but can be changed with the -d command line switch).

Here is how I compile such a set of .PNGs into an HD video. Your mileage may vary; the script discussed on this page is not an official part of the mfm distribution; it is provided only as a sample or starting point; if it breaks, you get to keep all the pieces.

MakeMFMMovie: Script overview

The MakeMFMMovie expects to find the path to an MFM simulation directory on the command line, such as: MakeMFMMovie /tmp/20140808134855 and, if all goes well, it writes out /tmp/20140808134855.mp4 .

In operation, MakeMFMMove does basically two things:

  1. Creates sequentially-numbered links to all the .PNGs in a 'vlinks/' subdirectory. This is needed because the simulation writes out PNGs named by the AEPS at the time of writing, which need not be (and usually aren't) strictly sequential.
  2. Runs ffmpeg (or now 'avconv') on those links to generate an H.264 video

See or download the full script at the bottom of this page.

bueoWfK7IKU At right is an example illustrating the 'fish sticks' shark stabilization strategy. That video was made with pretty aggressive acceleration and surge parameters (see next section) to reveal deep-time dynamics in a relatively short presentation.

Given that the '-p' switch causes the simulator to generate a .PNG each epoch, the primary relevant command-line switches are those that affect the size of an epoch:

Simulator command-line examples for making videos

The full MakeMFMMovie script

MakeMFMMovie
#!/bin/bash
 
function die {
   echo "$1"
   echo "Usage: $0 TOPLEVELMFMDIRECTORY"
   exit 1
}
 
function lookfor {
    for b in "$@"; do
	found=$(which "$b" 2>/dev/null)
	if [ -n "$found" ]; then
	    if [ -x "$found" ]; then
		echo "$found"
		return
	    fi
	fi
    done
}
 
ffmpeg=$(lookfor avconv ffmpeg)
if [ -z "$ffmpeg" ]; then
    die "Can't find ffmpeg or avconv.  Perhaps 'sudo apt-get install libav-tools'?"
else
    echo "Will use '$ffmpeg' for encoding"
fi
 
todir=`readlink -m "$1"`
viddir=$todir/vid
if [ ! -d $viddir ] ; then
   die "'$viddir' is not a directory."
fi
 
outfile="$todir.mp4"
touch "$outfile" || die "Can't touch '$outfile'"
if [ ! -w "$outfile" ] ; then
    die "Can't write '$outfile'"
else
    rm -f "$outfile"
fi
 
linkdir=$todir/vlinks
if [ -d "$linkdir" ] ; then
    echo "Deleting old '$linkdir'"
    rm -rf "$linkdir" || die "Can't delete '$linkdir'"
fi
 
mkdir -p "$linkdir" || die "Can't create directory '$linkdir'"
echo -n "Creating sequential symlinks in '$linkdir'.."
 
x=1
for i in $viddir/*.png; do
    counter=$(printf %06d $x)
    ln -s "$i" $linkdir/img"$counter".png
    x=$(($x+1))
done
sync
 
echo "done. $x symlinks created."
echo
echo "BEGINNING HD VIDEO GENERATION TO $outfile.  THIS MAY TAKE A WHILE!"
echo
 
$ffmpeg -f image2 -r 30 -vf pad="1920:1080:(ow-iw)/2:(oh-ih)/2:0x0f0f0f" -i "$linkdir/img%06d.png" -vcodec libx264 -r 30 -pix_fmt yuv420p $outfile