Wednesday, June 19, 2013

Tutorial - Recording Videos of Games under MAME

I include a video of myself playing some video game in almost every one of my posts. In addition to the videos I share here, I have a YouTube page where I have 19 videos as of this writing. You might be wondering how I record these videos. In this tutorial, I will explain different methods that can be used to record videos while playing some arcade game on MAME.

The methods that I will discuss will use MAME's built-in "-mngwrite" and "-aviwrite" options and therefore, will not require any additional software (though some additional software may be necessary for processing the video and audio files generated by MAME). I will just mention that there are software which can be used to capture videos from the screen. This process is called screencasting. These programs, such as FRAPS, will record anything you see on screen as opposed to MAME's built-in functions which only record the game screen. In other words, if you press the TAB button to access the options menu, this menu will be a part of the video that FRAPS records but the MAME video will not show this screen. My personal recommendation is not to use FRAPS or any other additional software unless the built-in functions of MAME do not work.

The options "-mngwrite" and "-aviwrite" tells MAME to record the output to a .mng and a .avi file respectively, but the common practice is not to use these commands while playing the game. The reason for this is that these commands, especially "-aviwrite", slows the system down considerably, sometimes to a point where it becomes impossible to play the game. A simple remedy for this problem is to record the input while playing the game and use the record commands while playing this recorded input.

MAME is capable of recording the user input and later playing these recorded input files. In other words, it is possible to create a replay file which contains all the moves you make while playing the game and can later be used to playback the entire recorded game. This is achieved using the "-rec" command. The usage is as follows:

mame -rec <filename>

To playback a recorded game, the "-pb" command is used in the following way:

mame -pb <filename>

Let me illustrate the usage of these commands on an example. Suppose a 64-bit version of MAME is installed in the directory " c:\mame" and you would like to play the game "Hard Hat" and record the input to a file named "input_rec.inp". The command you should enter is the following:

c:\mame>mame64.exe hardhat -rec input_rec.inp

This will create a file "input_rec.inp" in the "c:\mame\inp" directory. If you want, you can edit "mame.ini" file to change where the recorded input files are saved. To playback the recorded file, the following command should be entered:

c:\mame>mame64.exe hardhat -pb input_rec.inp

After entering this command, MAME will look for the "input_rec.inp" file in the "c:\mame\inp" directory and start the replay if this file is found. If this file is in some other directory, then you should enter the filename with the full path.

If there are problems with recording and replaying, you can try deleting the .cfg that belongs to whichever game you are playing. You should delete this file before recording and before the playback. This file is located in the "c:\mame\cfg" directory and the name of the file is the same as the name of the rom of the game. In the above example, the .cfg file will be "c:\mame\cfg\hardhat.cfg". You should also make sure that your version of MAME is the same as the version that was used to record the game.

After recording your input, you can use the "-mngwrite" command to write the recorded game to a .mng file, though it is claimed that this command stopped working on the newer versions of MAME. In addition, this command does not record any sounds from the game. Therefore, the "-mngwrite" command is usually accompanied by the "-wavwrite" command. The usage for these two commands is as follows:

mame -mngwrite <filename> -wavwrite <filename>

The files that were created by this command, by default, will be saved to "c:\mame\snap" folder. This, in addition to any other folder that MAME uses, can be changed by editing the "mame.ini" file in the "c:\mame" directory. You can also turn on/off recording of .mng videos by pressing SHIF + F12 anytime during the game, though with this method you will not be able to record any sound.

These commands can be used together with the "-pb" command. For example, suppose we want to make a video of the game "Hard Hat" from the recording "input_rec.inp" where the name of the video file is "video.mng" and the name of the audio file is "audio.wav". The command that we should enter is the following:

c:\mame>mame64.exe hardhat -pb input_rec.inp -mngwrite video.mng -wavwrite audio.wav

Now, after the playback, the files "video.mng" and "audio.wav" will be saved to the folder "c:\mame\snap". You can then use additional software to combine the audio and video files. There are free software that can be used for this purpose, such as MPlayer. I am not going to be able to offer any help about how to use this program, as this is not usually the method that I use to record my videos.

An easier way to record videos is to use the "-aviwrite" command. Unlike the "-mngwrite" command, the "-aviwrite" command will record both video and audio. The usage of this command is similar to the "-mngwrite" command:

mame -aviwrite <filename>

The files created with this command are saved to the "c:\mame\snap" directory as usual. For example, if we want to make a video of the game "Hard Hat" from the recording "input_rec.inp" where the name of the video file is "video.avi", the following command should be entered:

c:\mame>mame64.exe hardhat -pb input_rec.inp -aviwrite video.avi

After the playback, the file "video.avi" will be saved to the folder "c:\mame\snap". The avi files created by MAME are uncompressed and therefore they are extremely large (about 1gb per minute). You might want to compress these files, especially if you want to share these videos on Youtube or some other website. A free software that can be used for this purpose is Handbrake.

Finally, I will remark that throughout the tutorial, the assumption was that you are using the command line version of MAME, though user interface versions of MAME are also capable of recording and replaying game input and writing video and audio files; however I could not find a way to playback some recorded game and write a video file at the same time. In fact, that was the reason I started using the command line version.