TASVideos

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

Emulator Resources / Making AVI / Common / Windows

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 and guidelines for making AVIs on Windows systems.
It explains one method of many. Major contributors to this page: shinydoofy, adelikat, johannes, sp00ky, Raiscan, sgrunt

Requirements


You will need the following:
  • A recent version of MEncoder with H.264 support (see here for an alternate Win32 build). MEncoder is a free command line video decoding, encoding and filtering tool. It will be used for various preencode steps. It is a part of MPlayer, a media player which will be used during this process for playback.
  • FFDshow, a media decoder/encoder with Directshow and VfW support. It is our primary tool for capturing h.264 lossless video from emulator.
  • direct264, a custom build of the x264 command line encoder. It will be used for our final video encode once all steps are met, primarily due to it's support of a new command, deldup.
  • One of the following:
    • MKVtoolnix, a set of tools to create, alter and inspect Matroska files (mkv), a container format which will hold the finished audio and video streams.
    • MP4Box, a utility to create, alter, and inspect MP4 container files (MP4).
  • The appropriate emulator
  • The movie submission file - check the appropriate submission from the submissions page
  • MPlayer
  • oggenc2 or Nero AAC encoder
  • (optional) Encoding Utilities - contains all the scripts needed to do this tutorial.

Installation and initial configuration

  1. Download mencoder.exe, mplayer.exe, oggenc2.exe, and all Direct264 files to the same folder.
  2. MKVtoolnix: download and install. Browse to install location(default is C:\Program Files\MKVtoolnix), copy the mkvmerge.exe file to the directory where you placed MEncoder. If you are using MP4Box, place that in the same location.
  3. Emulator/Movie File: extract to a directory. Note that this article will not cover where to get ROM files.
  4. FFDshow: Download and install. During installation, install all components. For "select supported video codecs", make sure to select H.264. The rest of the options should be left to the default.
  5. Configuring FFDshow to capture: After installing, go to the start menu > ffdshow. Select VFW codec configuration. Under the encoding tab, select H.264 lossless. Under FOURCC, select H264. Other settings can be left on default. Select the Decoder tab now, and click Codecs in the left hand list. A new menu should now appear. Find H.264 in the list and make sure it is set to libavcodec by clicking on it in the decoder column.


Create initial h.264 lossless capture.


In the case of emulator specific settings, check the Emulator Settings - Windows article for help.
  1. Run the emulator and load the ROM.
  2. Increase the emulation speed to about 400% (the command to do this varies by emulator but often it is the '=' key). This will speed up this initial encode by making the limiting factor your cpu.
  3. Turn off frame display. Configure sound (This varies by platform, but typically it is the highest setting in the emulator, 48khz stereo, or 44.1khz stereo. In the case of NES it is 48khz mono). Pause the emulator and load the movie file.
  4. Select the Record AVI option. Select the MEncoder folder to save the AVI (or whatever workspace folder you like). Call it capture.avi and save. Select FFDshow in the dropdown box. Click ok.
  5. Unpause emulation. Record until the ending and one loop of the ending song if there is one that loops. Don't worry if you record a little extra afterward as you can clean it up with MEncoder in the next step.

Crop initial capture

If you recorded past the ending for a while you can fix the file in this step.

  1. Find the time you wish to end the video.
  2. Copy the following command line to notepad and save it as crop.bat:
mencoder.exe -oac copy -mc 0 -ovc copy -endpos x -o recorded.avi capture.avi

-endpos should be specified in hh:mm:ss. For example to end at 15:17 in the movie use -endpos 15:17

Run crop.bat to crop your file.


Encoding


This section covers encoding your video and audio.

Please check the guidelines under Encoder Guidelines before continuing if you have not. Especially read the logo section as we will cover it in the first step.

Using MEncoder to combine your logo and recording/add subtitles.

Your logo must be encoded in h.264 at 60 fps and the resolution should match the capture's resolution. The audio rate should match the audio rate of your capture as well. For the purposes of this article we will assume your logo is called logo.avi. Please read Emulator Resources/Making Avi/Logo/Windows for help with creating a logo.

First, we must create a subtitle file. Here is an example one:

   {60}{360}Super Mario Bros in 04:48.53|by klmz|Rerecord count: 4459
   {1501}{1701}This is a tool-assisted recording.|For more information, visit http://TASVideos.org/
Copy this to notepad and save it as subtitle.sub. Be sure to put in the appropriate information and double check that there are no spelling errors. The numbers before each line are the frames at which the subtitle will play.

Create a subfolder in your MEncoder folder, called 'mplayer'. Go to your c:\windows\fonts directory and find the times new roman bold font, or another font you'd like to use for the subs. Copy it to this new mplayer directory and rename it subfont.ttf

This command line can be saved as logocombine.bat:

start /wait mencoder.exe -aspect 4:3 -oac copy -mc 0 -ovc lavc -lavcopts vcodec=ffv1:vstrict=-2 -sub subtitle.sub -subfont-text-scale 4 -sub-bg-alpha 15 -o mixed.avi logo.avi recorded.avi

If you are encoding a handheld run, you can remove -aspect 4:3 from this.

You can add -subpos 20 to the video to move the subs to the top of the screen instead of the bottom. -subfont-outline 4 can be used in place of -sub-bg-alpha 15 to replace the black background around the text with shadowed text instead, which can look cleaner with some games.

This will reencode into another lossless format, which requires a lot of disc space. This reencode has multiple purposes, including forcing 4:3 aspect ratio (necessary for some formats, especially Final burn alpha games), resolving some known logo issues (for example NES games which run at 60.1 fps rather than 60 fps) as well as preparing our subtitles before our final encode.

Once done, test the file to make sure the subtitles are proper. Correct them if necessary and rerun logocombine.bat.

Encoding the video

With the logo-combined video at the ready, we can now turn this into our finished video stream. This process can take a long time so we will create a bat to automate it. Save this as encode.bat.

start /wait x264 "mixed.avi" --deldup 40 --crf 20 --keyint 300 --ref 15 --no-fast-pskip --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 10 --trellis 2 --partitions all --me umh --merange 64 --8x8dct --no-dct-decimate --output "encoded.mp4"

Advanced: Finding the best bitrate

Sometimes, --crf 20 may not give the best quality-to-file-size ratio. If this is the case, and adjusting --crf does not yield desirable results you will need to find a good bitrate to encode the video at.

This is a simple method to testing various bitrate settings on the video to determine a good bitrate for your real encode.

We will have MEncoder crop out a section of the video and create some test files.

This line will crop out the first 2 minutes of the video and save it as video-crop.avi, without sound.

start /wait mencoder.exe -nosound -mc 0 -ovc copy -endpos 00:02:00 -o Video-crop.avi mixed.avi

The following lines will then run a test encode on the cropped file with some slimlined settings at various bitrates. You can customize this by changing the :bitrate=: lines. It will then create video-testxxx.mp4 files, where xxx is the bitrate used.

start /wait x264 "Video-crop.avi" --deldup 40 --bitrate 350 --keyint 300 --ref 15 --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --partitions all --me hex --merange 30 --8x8dct --no-dct-decimate --output "video-test350.mp4"

start /wait x264 "Video-crop.avi" --deldup 40 --bitrate 320 --keyint 300 --ref 15 --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --partitions all --me hex --merange 30 --8x8dct --no-dct-decimate --output "video-test320.mp4"

start /wait x264 "Video-crop.avi" --deldup 40 --bitrate 300 --keyint 300 --ref 15 --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --partitions all --me hex --merange 30 --8x8dct --no-dct-decimate --output "video-test300.mp4"

start /wait x264 "Video-crop.avi" --deldup 40 --bitrate 280 --keyint 300 --ref 15 --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --partitions all --me hex --merange 30 --8x8dct --no-dct-decimate --output "video-test280.mp4"

start /wait x264 "Video-crop.avi" --deldup 40 --bitrate 250 --keyint 300 --ref 15 --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --partitions all --me hex --merange 30 --8x8dct --no-dct-decimate --output "video-test250.mp4"

Save all the lines to one file in notepad and call it samples.bat. Run it and allow it to create the sample files.

First view the video-crop.avi file to get a feel with the clip. Then watch the various encoded clips as a guide to figuring out the best bitrate. Keep in mind these are fast test encodes and not exhaustive, so use good judgement. Minor quality issues will look better in the final encode.

Things to watch for while viewing the clips:

  1. Blurriness in the background that suddenly sharpens, or comes "into focus". This is a sign that a higher bitrate is needed.
  2. Look for excessive encoding artifacts around the main character. Some are expected but it should not be extreme.
  3. Look for overall blurriness.
  4. Look for extreme 'streaking' when the main character moves among dark backgrounds
  5. Compare to the previous encode if there is one. You can also open the previous encode with a hex editor and search for 'bitrate'. This will point you to the header and you can get a feel for the settings the previous encoder used.

The key is to get the most 'bang for your buck' by setting the lowest bitrate that will give you a clean looking encode. You can estimate what the final filesize will be based on the filesizes of the clips.

Encoding the video at a specific bitrate

Now that you know what bitrate you want to use, we will run a 3 pass encode. This process can take a long time so we will create a bat to automate it. Save this as encode.bat. Remember to adjust the bitrate options based on your previous research.

start /wait x264 "mixed.avi" --deldup 40 --pass 1 --bitrate 350 --keyint 300 --ref 15 --no-fast-pskip --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --trellis 2 --partitions all --me umh --merange 64 --threads 1 --8x8dct --no-dct-decimate --output "encoded.mp4"

start /wait x264 "mixed.avi" --deldup 40 --pass 3 --bitrate 350 --keyint 300 --ref 15 --no-fast-pskip --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --trellis 2 --partitions all --me umh --merange 64 --threads 1 --8x8dct --no-dct-decimate --output "encoded.mp4"

start /wait x264 "mixed.avi" --deldup 40 --pass 3 --bitrate 350 --keyint 300 --ref 15 --no-fast-pskip --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --trellis 2 --partitions all --me umh --merange 64 --threads 1 --8x8dct --no-dct-decimate --output "encoded.mp4"

Check the encoded video to make sure it is up to snuff and that the file size is acceptable. If so it's time for audio.

Note for those using direct264: It is suggested that you use the --versioninfo command in your command line in the 2nd and 3rd lines (after --pass 3) as this allows future publishers to harvest the settings you used in your encode. This has the major benefit of making future publications easier as trial and error won't be needed to find the optimal settings.

Encoding audio

To encode the audio, you will first need to split the audio track off from the video. To use mplayer to do this, issue the following command.

start /wait mplayer mixed.avi -ao pcm:file=encoded.wav \ -vc dummy -aid 1 -vo null

Once this is done, you will need to encode the audio track in either OGG Vorbis or AAC format.

OGG Vorbis

Use of Vorbis will mean that the resulting audio file will not be streamable.

This command line can be used to encode the audio to an ogg file (save as audioogg.bat).

start /wait oggenc2 -q1 encoded.wav

-q is the rate quantifier, which may need to be raised on games with especially detailed sound.

AAC

AAC is preferred where the resulting file should be streamable. The Nero AAC encoder can be used as follows:

start /wait neroAacEnc -q 0.25 -if encoded.wav -of encoded.aac

-q is a quality factor, determining the bitrate of the final product relative to the complexity of the audio file. This may need to be adjusted for the best results.

Muxing the file

There are two container formats in current use by the site: MKV and MP4. MP4 is used where the final result is intended to be streamable (this must use AAC audio as opposed to Vorbis).

MKV

This command line will join your video and audio streams into 1 MKV. The main advantage of the MKV container is smaller filesize, though it also handles h.264 better than AVI does in general.

For Console games use aspect ratio correction:

mkvmerge --engage no_simpleblocks --aspect-ratio 1:4/3 -o final.mkv encoded.mp4 encoded.ogg

For handheld games:

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

The no_simpleblocks switch is IMPORTANT, as it resolves seeking issues with media players with outdated MKV support (VLC media player)

Test the file. If the quality is poorer than expected you may want to go back and reencode the video stream with a higher bitrate. If the audio is poor you should reencode the ogg with a higher q setting.

MP4

mp4box --add encoded.mp4 --add encoded.aac final.mp4

Advanced Encoding Options


The Direct264 CLI used in this article for the final encode has many advanced options. This page covers the basic x264 options in depth. This post by the author covers the additional functions he has added. Here is a breakdown of the options used in the encoding command line in this article:

x264 "mixed.avi" --deldup 40 --crf 20 --keyint 300 --ref 15 --no-fast-pskip --bframes 6 --b-adapt 2 --mbtree --weightb --direct auto --subme 9 --trellis 2 --partitions all --me umh --merange 64 --threads 1 --8x8dct --no-dct-decimate --output "encoded.mp4"

  1. deldup 40: Major space saver. This is similar to -vf decimate in mencoder but works well with b frames and produces much better encodes. 40 specifies that the minimum fps will be 40 (prevents stuttering from decimating too many frames).

  1. crf 20: One of the most important settings; this indirectly determines the final bitrate (and therefore filesize) of the file. Lower numbers here will increase quality and file size; the lowest is 0, which yields lossless video (may not be compatible with YouTube and the like). 20 is what our encoders normally use; you may need to adjust this for desirable results.
  2. keyint=300: Maximum frames between keyframes, which take up more space. Setting this too high can interfere with seeking and possibly interfere with encoding/decoding quality. This setting saves a tiny amount of space over the default, which is 250. A value higher than 300 is not recommended.
  3. Frameref: This sets the number of frames the encoding process can reference for internal predictors. High values are best for fast moving content such as games. The maximum value is 16, however this setting can be incompatible with some decoders, so 15 is a safe bet.
  4. no-fast-pskip: Fast pskip (which is on by default) speeds up the encode at the cost of possibly losing some quality in quiet areas like sky or backgrounds. For our purposes it should be disabled, but you may want to leave it enabled for test encodes.
  5. bframes 6/b-adapt 2/mbtree/weightb/direct auto: B frames are smaller reference frames that can help make areas without any/much movement look better and save filesize. the maximum value is 16, however high values can cause seek issues in some media players, and it is rare that more than 5 are used. 6 is an excellent medium. The other settings just ensure b frames are used optimally.
  6. Partitions all/8x8dct: These settings affect macroblock partitions, reducing the amount of blocking done by the encoder. These are the best settings and should not be changed.
  7. me umh/subme 9/merange=64: Motion estimation routines. There is a higher setting of me=esa which performs an exhaustive search, but this brings the encode to a crawl for no perceptible quality gain even in our fast moving content. subme 9 is the equivalent of the old subme=7 from older articles. Newer implementations use subme 9 to also enable other optimizations. merange is the search range used by motion estimation. 64 is the maximum value however it is much slower, and you can get away with a much smaller value on older games or ones without much movement. The default is 16.
  8. trellis 2: Helps optimize motion estimation. This setting is the slowest but has the best performance. In some extreme cases trellis 1 makes a huge difference in encoding speed. This setting can sometimes interfere with dct-decimate (on by default) causing artifacts due to the 2 prediction routines interfering with one another.
  9. threads 1: This sets the encoder to only use 1 cpu. Although multi core encoding is faster, it has a quality penalty.
  10. no-dct-decimate/no-pnsr: dct decimate optimizes p-frames by attempting to remove some details it deems unnecessary. However this can interfere with the trellis setting which is why I disable it by default. Psnr prints the signal to noise ratio statistics log after the encode is complete. Disabling it is a tiny bit faster but perhaps imperceptible considering how long our encodes are.

Settings not used but of interest

  • zones: For extremely advanced encoders. Zones allow you to set sections of the video to get more or less quality. For example you can reduce the quality of the opening and credits, and add quality to an especially fast moving section or boss fight. Read the MPlayer documentation to familiarize yourself with this command.
an example command line is

--zones 0,300,b=0.80/1200,1350,b=1.05/1500,1600,b=0.80

This will specify that frames 0-300 (an opening of a test video) and 1500-1600 (the text only end credits of the video) only use 80% bitrate, allocating the rest of the resources to the rest of the video. Frames 1200-1350 (a fast moving boss fight) are set to use 105% bitrate.


Double checking your encode


The file size ratio must be good.

For older consoles, filesize to length ratio should ideally be no greater than 4MB per minute. For example, most NES encodes will be between 1 and 2MB/minute; GB encodes will be smaller, and newer platforms such as PSX may be slightly larger. If your file is well outside this ratio, you should double check your encoding process.

Video quality must be good.

This is subjective, but you want to look for background "refocusing" - where pieces of the background become blurry over time, and suddenly sharpen back into focus. Make sure there is detail in the backgrounds. Look for "streaking" of moving objects - where a moving object (such as the main character) leaves a trail behind him of blurry or different color background. Due to the use of h264, there will be some small artifacts on moving characters, as well as some slight blurriness of text. This is normal and acceptable in small quantities. However, if it is too blurry, then it needs to be encoded again.

Audio quality must be good.

Common audio problems include:

  • High frequency artifacts due to low bitrate
  • The audio is too quiet (usually resulting from the volume control of FCEU being set low), or audio drift.
  • Audio drift is where the audio is progressively more offset from the video.

Subtitles must be correct.

Double check that the subtitles have no errors (spelling or otherwise) and that the information is correct. Double-check that the subtitles are placed in a good spot. If you find an error at this stage, unfortunately, all video passes must be redone.

If all of these things check out well, then congratulations, you are finished! If you are a publisher, the next step is to review the PublisherGuidelines. If you are not, then you want to review the AVI file name section of the Publisher Guidelines, name the file appropriately (as a courtesy), then get the file into a publisher's hands.

TODO Cover more options not used during encode, clean up last section

TODO: better document aspect ratio


RSS
EmulatorResources/MakingAVI/Common/Windows last edited by sgrunt on 2010-03-15 21:44:32
Page info and history | Latest diff | List referrers