This is an old revision of the document!
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 /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 displayed is not an official part of the mfm distribution, and is provided only as a sample or starting point.
The MakeMFMMovie script
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:
- Creates sequentially-numbered links to all the .PNGs in a 'vlinks/' subdirectory
- Runs ffmpeg (or now 'avconv') on those links to generate an H.264 video
Here's the full script:
#!/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