TASVideos

Tool-assisted console game movies
When human skills are just not enough

Emulator Resources / Making AVI / Common / Linux

This page is part of the Emulator resources / Making AVI page collection. Back to:
<< Emulator Resources / Making AVI / Common
<< Emulator Resources / Making AVI
<< Emulator Resources

This page lists common requirements for making AVIs on Linux systems.
This was written by me, Bisqwit, and explains my method. There are certainly many ways to accomplish the same outcome.

Requirements

You will need the following:
  • Familiarity with using commandline in Linux
    • Ability to use the package manager of your distribution
  • X11 window system (if you don't know what it is, you have it)
  • A recent version of MEncoder with H.264 support
  • GNU toolchain for software development (gcc, g++, libstdc++, make, libtool, autoconf, and the like)

Getting MEncoder

Package manager

You can install MEncoder from your distribution's package manager. However, in case of distributions that are not frequently updated, it may be possible that your MEncoder version is too old. Or possibly built with wrong settings. In such cases, we recommend using the repository versions instead.

Note that if you're going to compile everything from source, you might need to get Yasm for x264.

Getting from repository

  1. Make yourself root.
  2. Ensure that you have SubVersion (svn) and Git (usually either git-core or git). Get them from the package manager if you don't have them.
  3. Go to /usr/local/src/, and create a directory mplayer there. Go to that directory.
  4. Download the latest x264 source code from the x264 Git with the following command: git clone git://git.videolan.org/x264.git
  5. Compile and install x264: cd x264; ./configure; make; make install
    • Do those commands individually for better understanding on what goes wrong, if something goes wrong. I.e. don't just copypaste it.
    • If it complains of some missing dependencies, fulfill those dependencies by installing the relevant packages using your distribution's package manager and try again.
  6. Download the latest MEncoder source code from the MPlayer SVN with the following command (remember to go back to /usr/local/src/mplayer): svn co svn://svn.mplayerhq.hu/mplayer/trunk mplayer.
    • After it is done, rename the mplayer subdirectory into main. This is not necessary, but decreases chances for confusion.
  7. Compile and install mplayer: cd main; ./configure; make; make install
    • Do those commands individually for better understanding on what goes wrong, if something goes wrong. I.e. don't just copypaste it.
    • If it complains of some missing dependencies, fulfill those dependencies by installing the relevant packages using your distribution's package manager and try again.
    • If the compilation fails, try again at some later date. SVN code is occasionally broken.

Now you have a x264-capable mencoder.

Overall description of the encoding procedure

The overall procedure for encoding a movie goes like this:

Step 0: Locate the ROM necessary for the playback of the movie, and download the movie file.

Create initial encoding

Step 1: Run a script that launches the emulator and runs the movie.

The script will instruct the emulator to launch MEncoder, to create an initial encoding of the movie. That initial encoding is labelled as test0.avi, and it is at a nearly lossless quality. It is not distributed or uploaded to the TASvideos site, but it is the basis for further encoding passes.

Create subtitles for the movie

Step 2: Run a script that reads the movie file and creates a template for the subtitles of this particular movie.

The script will read the frame count and authorship information from the movie file specified, and output a subtitle file (test0.sub) in which that information is denoted.

Step 3: Edit the subtitles.

Adjust the timings of the subtitles, and correct the game name and authorship, as necessary.

For example, for this particular movie, the subtitles created by the script are as follows:

   {60}{180}Adelikat, Deign, Cardboard, JXQ|Played by ?|Playing time: 0:47:33.52|Rerecord count: 78061
   {192}{312}This is a tool-assisted recording, played on an emulator.|For details, see http://TASvideos.org/
I changed them as follows:
   {120}{240}Super Mario Bros 3 without flutes|Played by Adelikat, Deign, Cardboard, JXQ|Playing time: 0:47:33.52|Rerecord count: 78061
   {252}{372}This is a tool-assisted recording, played on an emulator.|For details, see http://TASvideos.org/
The list of changes I did are:
  • Made the subtitles appear 1 second later so they won't pathologically overlap with the encoding logo / game title.
  • Moved the author names after the "Played by " text
  • Added the movie description.

Adjusting the encoding script for the movie

Step 4: Specify encoding parameters

My actual encoding script (after the initial encoding) consists of two components:

  1. nesvideos.cfg, which configures the encoding
  2. ENCODE, a shell script that does the actual bulk of the encoding work.

A sample script looks like this:

   BR=240
   QSCALE=32
   FILES="test0.avi"
   OTHER="$OTHER -endpos 49:49"
   FINAL="supermariobros3-tas-warpless-adelikat,deign,cardboard,jxq.avi"
In this file, I have determined that the target bitrate for the video will be about 240 kbit/s, and that only the first 49:49 of the movie will be encoded, discarding the rest.

Run the encoding

Step 5: Launch the encoding

After steps 0-4 are done, it is time to launch the encoder. It is done by executing the ENCODE script.

Do not click it open from some desktop icon. Instead, use your terminal (all of this so far should have been done in one terminal), go to the directory where your nesvideos.cfg and test0.avi files are, and execute the ENCODE script by giving its relative path.

In my system the paths work as follows:

  • $HOME/nes/fceu: This is the directory where the initial encoding takes place. It contains the ROM, the movie file, and the RUNEMU script.
  • $HOME/nes/xgetimage: This is the directory where the subtitle generator (GENSUB) and encoder (ENCODE) scripts reside.
  • $HOME/nes/xgetimage/smb3: This the directory where the bulk encoding work happens. After the initial encoding, I have moved the test0.avi into this directory.

So the work so far is like this:

   cd ~/nes/fceu
   ## Acquire movie file:
   wget http://tasvideos.org/fcm/123456.zip
   unzip 123456.zip
   rm 123456.zip
   ## Change the filename to be easier to handle
   mv 'Weirdly named movie file.fcm'  smb3u.fcm
   ## Run initial encoding
   ./RUN smb3u.fcm smb3u.nes
   ## Initial encoding done, start actual work
   mv test0.avi ~/nes/xgetimage/smb3/
   cd ~/nes/xgetimage/smb3
   ## Generate subtitles (note the relative path):
   ../GENSUB ~/nes/fceu/smb3u.fcm
   joe test0.sub              # Note: joe is an editor.
   ## Check encoding settings:
   joe nesvideos.cfg          # Use nano/joe/vi/emacs/whatever.
   ## Start encoding. Note the relative path.
   ../ENCODE
   ## Done!
After this work, check out the working directory. The newest AVI file in that directory should be your produced AVI file.
  • If errors happened, diagnose and fix them and try again.
  • If the AVI quality is unsatisfying, remedy the problem and try again.

Alt Step 5: Creating an MKV file using x264.

To make an MKV file using x264 you will need to first decode the video using mencoder and pipe the raw video through a named fifo to x264, you must do this because x264 does not support avis input under Linux (you will probably want to change the bitrate to something appropriate for the game. Here is a command that will do just that. (This is tuned to NES video settings for pass 1 as an example)

   mkfifo s.log ; mencoder -nosound -vf format=i420 -ovc raw -of rawvideo  \
   -ofps 60.100 -o s.log -quiet "mixed.avi" & x264 s.log --pass 1 --slow-firstpass \
   --preset placebo --bitrate 300 --keyint 300 --fps 60.100 --output "encoded.mp4" \
   256x224 ; rm s.log
Then you will need to pull out the audio and re-encode the audio as ogg.

   mplayer mixed2.avi -ao pcm:file=encoded.wav -vc dummy -aid 1 -vo null ; oggenc -q1 encoded.wav
And finally you'll want to zip the two files together into an mkv. (You may need to download the source and compile it yourself if your version is old and does not support the no_simpleblocks hack. The source can be obtained through git, git clone git://git.bunkus.org/mkvtoolnix.git)

   mkvmerge --engage no_simpleblocks -o final.mkv encoded.mp4 encoded.ogg

RSS
EmulatorResources/MakingAVI/Common/Linux last edited by OmnipotentEntity on 2009-09-22 08:49:14
Page info and history | Latest diff | List referrers