User Tools

Site Tools


introduction:making_an_mfm_video

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.

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:

  • -e NUM set the epoch length to NUM AEPS.
  • --accelerate NUM the epoch length by one every NUM epochs. When this switch is used, the epoch length at the beginning of the simulation is the initial epoch length.
  • --surge NUM increment the acceleration every NUM epochs. When this switch is used, the acceleration at the beginning of the simulation is the initial acceleration.

Simulator command-line examples for making videos

  • mfms -p – Save a screenshot every epoch, which defaults to 100 AEPS
  • mfms -p -e 1 – Set the epoch length to 1 to save a screenshot every AEPS. Since MakeMFMMovie encodes video at 30 frames/second, this implies each second of the video will show 30 AEPS, so the video will display the simulation results at 30 AER (regardless of how fast or slow the simulation actually ran when the data was generated).
  • mfms -p -e 0 --accelerate 30 – Set the epoch length to 0, but increment it every 30 epochs. (Since 0 epochs is considered a multiple of 30, the epoch length gets incremented to 1 immediately.) This causes the first second of video to run at 30 AER, the next second to run at 60 AER, and so on. After 5 seconds, for example, a total of $30+60+90+120+150 = 450$ AEPS will have passed in the simulation; after t seconds of video, $30t(t+1)/2$ AEPS will have passed. Videos made with a non-zero acceleration parameter are said to display in quadratic time.
  • mfms -p -e 0 --accelerate 30 --surge 90 – Same as the previous case, except also increment the acceleration every 90 epochs. Videos made with a non-zero surge parameter are said to display in cubic time.

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
Starting TLS failed
introduction/making_an_mfm_video.txt · Last modified: 2014/09/07 15:51 by ackley