21 July, 2008

Record movies in HL2/CS:S efficiently?

Ok, it seems many people don't know how to do this, so I will explain how this is done. All you need are the game itself, VirtualDub , and the trial of DivX Pro, which can be downloaded. NOTE: When I say to type something such as "record [filename]" in the instructions, I mean type it without the quotes. When I say click 'File > Open video file', I mean click the File menu, then the next option, which would be 'Open Video File' in that case.

Step 1: Recording the Movie in Half-Life 2 / Counter-Strike : Source as a Demo
(If you already have the demo file you want, skip to Step 2)

Open the game, and when it's time to record, open the console by pressing the tilde (~) key. Type "record [filename]" and press 'Enter'. Replace '[filename]' with whatever you want the demo to be titled. When you're done recording, open the console again and type "stop".

When you're ready to leave the server and start Step 2, read on.

Step 2: Converting the Demo to TGA Files

Change your video resolution in-game to whatever size movie you'd like. I use 640x480 since no larger is really necessary, and a single 640x480 frame is 900KB, which means 1/3 of a second of a 30FPS movie is 9MB. 1 second = 27MB. Huge, huh?

Then change your audio (if you want the audio to be recorded at all) to 2 speaker, and not headphones or 5.1 or whatever. You can leave the Options window open if you'd like.

Open the console. Type "host_framerate #" and press 'Enter'. Replace '#' with however many FPS you want the movie to be. I suggest 30 - it's rare any higher is necessary, and again, 1 second @ 30FPS = 27MB. Higher FPS = higher movie size.

Then in the console, type "startmovie [filename]", and hit 'Enter'. Replace '[filename]' with whatever you want the movie files to be called. This can be the same as the demo name, it doesn't matter.

While still in console, type "playdemo [filename]", and hit 'Enter'. Replace '[filename]' with the name of the demo you want converted. At this point, the demo will start, the frames will be rendered slowly (you'll experience 5 to 20 FPS most likely), and will be saved off as TGA images (many of them... host_framerate X length of demo in seconds).

When the demo is done and you're back at the menu, open console and type "endmovie", and hit 'Enter'. This will end the capture. If you don't enter this command, the menu of CS:S or HL2 will be recorded as additional 900KB+ frames. We don't want that, now do we?

Close the game. Go to Step 3.

Step 3: Putting the TGAs Together into an AVI

At this point, I'm assuming you downloaded and extracted VirtualDub. If not, go back to the top of this page.

Open VirtualDub, and click 'File > Open video file'. Navigate to the folder of the game (in CS:S, this will be the cstrike folder). Make sure 'Image Sequence (*.bmp, *.tga)' is selected in the 'Files of Type' drop down menu. Double-click the first image of the record sequence. There will be HUNDREDS (maybe thousands) of these images, double-click the first one.

VirtualDub will read them and begin piecing together a movie. We're not done yet, though!

Choose 'Audio > WAV Audio...'. If you can't select it, choose 'Audio > Full processing mode' first, then 'WAV Audio...'. In the same folder as the TGA image sequence, there will be a WAV file titled similarly to the images. Double-click this WAV file. VirtualDub will attach it to the movie.

Now, if you want to chop out parts of the movie, do so by finding the beginning frame of the part you want chopped and press 'Home'. Then find the last frame of that part and press 'End'. Then press 'Delete'. Do this with all useless / pointless parts of the movie. The WAV will also be chopped up, which is why it is important that the WAV be inserted before chopping!

Once you're done editing, it's time to set compression. If you don't want to compress, or want to use another program to do it (WM Encoder, for example), just click 'File > Save as AVI' and you're done. But if you want it to be small, and not the 500MB+ file an AVI itself is, you need compression. So, make sure DivX is installed, then continue.

Choose 'Video > Compression'. Choose the DivX codec, and click 'Configure'. Select 'Slow' from 'Encode Performance' - this will yield a slower processing time, but a better quality video with better compression, which means a smaller file to download. Click 'OK', then 'OK' again to leave the VDub compression dialog box.

Now choose 'Audio > Compression'. Choose 'MPEG Layer-3' from the list on the left, and a bitrate (preferrably stereo of some sort) from the right and click 'OK'.

Choose 'File > Save as AVI'. Locate where you want it saved, and what you want it called, and click 'Save'. VirtualDub will now work on compressing the video into a nice little DivX-based AVI file. Enjoy!