TASVideos

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

Deleted Pages / Emulator Resources / Making AVI / Common / Windows

This page is deleted and archived - not a part of the current site.

Use the “page info and history” feature to peer into past versions of the page. See DeletedPages for details.
This page is part of the Emulator resources / Making AVI page collection.
Back to:
<< 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 and possibly Flygon (Depending on how you look at it).

Table of contents [expand all] [collapse all]

Requirements


You will need the following:

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. You should use a lossless codec to capture video. Historically, this has been h.264 lossless, but if you are interested in capturing screenshots (which is much easier for the encoder to do) you will want to select a codec which supports the RGB32 colourspace (which h.264 does not); with ffdshow you can use FFV1 (in the configuration options, set Encoder to FFV1 and Colorspace - under Generic - to RGB32), or you can use alternate lossless RGB codecs such as Camstudio. When in doubt, use one of those two codecs.


Create initial 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 (or your preferred RGB lossless codec) in the dropdown box. If you have not configured your codec (especially if it is FFDshow), do so now (see 5 under Installation and Initial Configuration for FFDshow options). Click OK when you are done.
  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 with one of the two following steps.

TODO: Put the MEncoder and VirtualDub into separate tabs - I've had massive issues trying to put these into their own tabbed table

Method using MEncoder

  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.

Method using VirtualDub

  1. Open the video in VirtualDub
  2. In the Video menu set the mode to Direct Stream Copy
  3. Select the frame you want the AVI to end at and select Set selection start from the Edit menu
  4. Select End from the Go menu then select Set selection end from the Edit menu
  5. Press the Delete key on your keyboard to remove the redundant video data
  6. Select Save as AVI... from the File menu and save the resulting AVI as capture.avi

Although more complicated than the MEncoder process, it allows much more precise control on the resulting cropped AVI. This is also a very good and effective way for finding out what frames you want your subtitles to appear during for the next step.


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'. Copy a .ttf into the directory as subfont.ttf; this font will end up being used as the subtitle font. (Try to use something relatively plain, such as Arial.) This command line can be saved as logocombine.bat:

start /wait mencoder.exe -aspect 4:3 -oac copy -mc 0 -font subfont.ttf -nofontconfig -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 0 -subalign 0 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 --versioninfo --output "encoded.mp4"

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.

Finding the best bitrate

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.

Using MEncoder 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.

Using VirtualDub

Open the mixed AVI, go to the File menu, go to Save WAV and save the WAV as encoded.wav into the same folder.

TODO: Make the VirtualDub guide more professional sounding... and yes, it really is faster and more efficient, if it wasn't I wouldn't bother adding it into this guide. -Flygon

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.

Use of AAC will introduce a small audio delay into the final stream of around 100ms; if you are concerned with precise synchronisation with the video track, you should truncate the appropriate length of audio from the silence during your logo.

You can use MP4Box to check what the audio delay is:

MP4Box -info encoded.aac

Once this is done, you can either use your favourite audio editing software to trim the silence from encoded.wav, or you can simply redump it while passing mplayer the -ss argument with the length you found above:

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

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.

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).

MP4

mp4box -add encoded.mp4 -add encoded.aac final.mp4 -par 1=<par>

<par> above is resolution-dependent; omit -par for handheld platforms.

  • 256x224 (NES/SNES): 7:6 (1.167)
  • 320x224 (Genesis): 14:15 (0.933)
(To compute this for an x by y resolution, use the formula y/x/3*4 and find the corresponding fraction.)

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.

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"

  • 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).
    • deldup 0.1:0.1:100:1:0.1 actually seems to get the minimum frame rate possible without actually dropping any non-duplicate frames, it does mess with the video players playback bar but it does actually play back perfectly, a few encodes have already been published with absurdly low deldup settings as it is anyway. You can thank Aktan and sgrunt for this revelation.

  • 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, numbers between 18 and 23 are recommended.
  • 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.
    • I've used values as high as 600 and haven't had any complaints from other people, it's a safe bet to say that this is as high as you'd want to go. Flygon
  • 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.
    • I've encoded several movies with 16 and haven't seen anyone complain, so it's safe to say it isn't a large issue. Flygon
  • 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.
  • 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.
    • 16 is the number I've used for all of my recent encodes and haven't seen anyone complain so far, it's a fair bet to say that it's a safe number. Flygon
  • 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.
  • 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 recommended 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.
    • The above information for the merange cap is mostly incorrect, there is several published encodes with a merange as high as the games resolution, essentially, if it was a NES game, the merange would be 256, or a Mega Drive game would be 320. There have been no complaints from other viewers. I've also encoded a Nintendo DS game with a merange of 384 and had zero issues with it. Flygon
  • 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.
  • threads 1: This sets the encoder to only use 1 cpu. Although multi core encoding is faster, it has a (fairly minor, and personally, impossible to see Flygon) quality penalty. No quality penalty occurs when using a crf value of 0.
  • 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.

TODO: Condense the scrutinization properly into the descriptions, and properly correct some technically incorrect facts, though, the merange thing is actually a bit of a heated argument Flygon

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.

  • rc-lookahead: For some reason this isn't maxed out at 250, it doesn't seem to reduce the encoding speed by much and it does seem to improve the filesize by a bit, basically, chuck the below command somewhere inside your script and forget about it. The default is 40 by the way.

-rc-lookahead 250



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:

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


Combined RSS Feed
DeletedPages/EmulatorResources/MakingAVI/Common/Windows last edited by sgrunt on 2010-10-02 16:41:19
Page info and history | Latest diff | List referrers | View Source