Portal 2

Portal 2

189 ratings
How to create a high-quality YouTube video from your gameplay
By Bisqwit
This guide teaches you how to make really good quality full-HD recordings from your gameplay on YouTube, for e.g. making walkthrough videos.
   
Award
Favorite
Favorited
Unfavorite
Purpose and background
The purpose of this guide is to teach how to make high-quality HD videos from your game play and to publish them on YouTube.

Requirements:
  • You need to be using Steam and your game on a Windows machine.
  • Your computer does not need to be fast enough to render HD game content in real time. You can do this on the lowest-end computer that can run your game.
  • You will need disk space. How much, it depends on the method we are using, but if you have less than 2 gigabytes, things will be very awkward for you. It is recommended to have several hundred gigabytes of free space. The simpler method only requires 2 gigabytes (at most; depending on your video).

This guide is designed for use with Portal 2, but it also works with all Orange Box games (Half-Life 2 series, Portal 1, Team Fortress 2), in mods thereof (such as Black Mesa), and in probably many other Source engine games as well.
GoldSrc games have a very similar mechanism, but with slightly different commands.
Recording your gameplay as .dem files
First, your gameplay will be recorded as .dem files. These "demo" files are very small files that simply tell the game how to reproduce your gaming session. These demo files require that the game and the map are installed on the computer where the demo is replayed, and thus they cannot be directly uploaded to YouTube.
There is a distinct advantage to using the .dem files: You can record them at what ever video quality settings you want, then go change the video settings, and replay the demo, and the demo will be replayed using the changed video settings.

For most fluent and jitter-free demos, it is recommended to use lower rendering settings than you would usually use! Don't worry, this will not be seen in the video. Use whatever settings you require, to get the game to render at over 30 FPS framerate at all times, even during times of heavy action and scripted scenes. Personally I use a smaller screen resolution, low or medium shader level, and 2x or no antialias.

To begin recording a .dem file, you must first enter the developer console in the game. This is done with \, §, ½, ` or some other hotkey, which you configure in your game's input settings.

You must be in-game already. Hit the developer console key, and the developer console will appear. The game will also be paused. Within the developer console, enter the following command to begin recording the demo:
record yourdemoname
Now a demo recording has been started. Exit the developer console by hitting ESC, and all your gameplay will be recorded.

When you're done playing, use the console command
stop
to end the recording.

Please pay attention to these few significant gotchas:
  • If you die and the level restarts, the demo recording will automatically end. You must manually begin recording a new demo, or your gameplay will not be recorded. (This does not apply to coop maps.)
  • If the game loads a new level, or you use the "Restart Level" menu option, the demo recording will automatically end, but the game will automatically start recording a new demo.
  • Everything that moves on its own: Objects you carry, elevators, enemies, and so on, will be recorded into the demo at the framerate that your game played. If you experience lag, there will be troubles when you replay the demo. You must use low enough graphics settings that there will not be lag.
  • When you use the "record" command, you must give a different name for each new file that you record. If you use the same name as before, your old demo will be silently overwritten and cannot be recovered.
Adjusting your game's rendering settings
After you have done recording your .dem files, you will want to crank up the rendering settings to the highest possible that you can use. Go to Options, Video, Advanced Video, and set everything to the maximum. (You do not need Wait for Vertical Sync though.)
Then go Apply, and go Back, and use the highest resolution that fits on your monitor.

  • If your display card does not support antialias, use the highest possible resolution. Period.
  • If your display card does support antialias, and it can do a resolution 1920×1080 or higher, use 1920×1080. There is no need to select higher than that, because YouTube will only display up to 1080p.
    • Well, there is the "Original" option. If you are aiming for that, then by all means use e.g. 2560×1440 if you can. It is recommended to aim for 16:9 resolutions though, because that is what the screens of most people are today. If you shoot in 2048×1536 (aspect ratio 4:3), and the viewer uses 480p mode, they will get 640×480 video, worse than if you had used 1920×1080 (848×480).
  • If your display card does support antialias, but it cannot do resolution 1920×1080, then select 1280×720. There is no need to select higher than that, because if your video is not 1080p, the highest YouTube will provide is 720p.
  • If your display card does support antialias, but you cannot do 720p, just select the highest resolution that you can.
  • If you are on a laptop, but you have an external monitor that supports higher resolutions than your laptop does, it is recommended to set the external monitor as a "primary desktop" in Windows, restart Portal 2, and then see which resolutions you can select in Portal 2.
  • Personally I use "Run in a Window" for "Display Mode"; this simplifies the usability somewhat, but it is not required to do that.

Don't worry if your game becomes horribly laggy and sluggish because of these video settings! It does not matter. The way we are recording the video from the .dem file is immune to all kinds of lag. The game may run slowly, but the video will look perfect and not laggy at all.
Installing codec(s)
If your video is just a few minutes long (1-5 minutes), it is feasible for you to use the AVI recording method described below.
For that, you need to install the X264 codec. X264 currently provides the best quality/size ratio out of all freely available video codecs.

Go to: http://sourceforge.net/projects/x264vfw/ , click on Download, and do not be confused by the nasty advertisements that try to lure you to click them instead of pursuing your mission. Download the x264 installer, and run it.
Once you have installed the x264 codec, you may need to restart Portal 2.

Just in case your video is longer than 5 minutes, or after trying the AVI recording method you find out that your AVI would have been longer than 2 gigabytes, I also recommend that you install VirtualDub: http://sourceforge.net/projects/virtualdub/ , VirtualDubMod: http://en.wikipedia.org/wiki/VirtualDubMod or MEncoder (if you're an avid text-mode UI user).
For short movies only: Using the AVI recording method
If your video is short, or if you will configure low enough codec settings, you can use the AVI recording method.

Enter the developer console, and enter the following commands:
sv_cheats 1 host_framerate 30 startmovie yourmoviename AVI

The command "host_framerate" forces the game to always render at perfectly 30 frames per in-game "second". This is very important. Otherwise you will get broken videos (audio / video desync).
  • Use 30, if you are publishing to YouTube or Vimeo or if you don't know where you will upload your video. There is no need to use a higher value, because YouTube clamps it at 30.
  • If you use Dailymotion or some other service, it may make sense to use 60.
The command "sv_cheats 1" simply enables the "host_framerate" command to be used.

After you enter the "startmovie" command, you will get a pop-up window asking you to choose your video codec. Choose "x264vfw" and then click the "Configure" button (third button from top). You may have other options there depending on what you have installed on your computer.
In the configuration window, there are several settings that you need to pay attention to.

  • It is very important that you check the "Zero Latency" checkbox. If you don't, you will get audio/video desync in your video.
  • Next, choose a value on the Ratefactor sliding scale. This will control how good your video looks, much like the JPEG quality setting. A value of 1.0 is nearly lossless, but it also produces huge files. A value of 51.0 stands for "smudged beyond recognition". The reasonable values are between 8 to 23.
    • Theoretically, you want to use as high quality (small number) as possible. However...
    • If you run into the 2 gigabyte AVI file size limit (your resolution is large or video is long), you must use a lower quality value (larger number).
    • If you don't want to wait a long time for your upload to YouTube, you need to use a lower quality value (larger number).
  • Check the "Preset" options in the top-left corner. Choose an option that matches your needs for production time. A slower option will produce a smaller AVI file. I recommend the "fast" or "medium" options.
When you are done, click "Ok" to confirm the settings, and click "Ok" to confirm the codec. You are back in the game's console window. You may get a warning: "DIVX only for now". Ignore it; it does not matter.

Now type the following command to start replaying your game:
playdemo yourdemoname
The console window will automatically close, and your demo will replay.
Note: You will not hear any sound! The sound will be redirected into the video. This is NORMAL.
The game may also appear to play very fast or very slow. This too, is NORMAL. Do not be concerned. The video will look perfectly normal.

While the demo plays, you can freely use other applications on your computer. Just click away. (This is why replaying in Window mode rather than Fullscreen is a good idea.) Be careful to not bring up the Steam overlay on your game, or it will be rendered in the video.

When your demo finishes, the console window will appear again, waiting for your commands.
You may type another "playdemo" command, and the other demo will be appended into your video. Or you may type
endmovie
, which ends the video recording.
After you type "endmovie", Portal 2 will produce weird sounds and be unresponsive for a minute or two. Do not be concerned. This too, is NORMAL (however odd).

REMEMBER to use the "endmovie" command. If you close the console without using the "endmovie" command, and you navigate the menus, the menus will be recorded in your video but at a wrong speed. Additionally, if you close the game without using the "endmovie" command, your AVI file may end up being broken.

Check your AVI file. You can find it in the "Portal 2" game folder on your computer.

IMPORTANT note: If your AVI file ends up being larger than 2 gigabytes, the Source engine will provide no warning whatsoever, but the file will end up being completely broken and unusable. YouTube has no problem with over-2 gigabyte files, but the problem is that this file is broken, because of a bug in the Source engine.
To work around this problem, you may try the following options:
  • Use a smaller screen resolution. This will produce also smaller videos.
  • Record a shorter video.
  • Use higher compression settings in the X264 configuration window (larger ratefactor value, slower preset). This will make the AVI file smaller.

If your video file was smaller than 2 gigabytes, you can now upload it to YouTube, or you can preview it, or you can postprocess it in a video editor, or you may want to re-record it using different quality settings.

Do not forget to restore your favourite video settings for playing the game the next time. You may also want to give the command,
host_framerate 0
to restore normal game speed throttling.
For arbitrary long movies: Using the TGA recording method
If your video is long (say, over 15 minutes) and you simply cannot find such encoding settings that the AVI file would be smaller than 2 gigabytes, you will need to use the TGA recording method.
It is almost the same as the AVI recording method, except for a small difference:
sv_cheats 1 host_framerate 30 startmovie yourvideoname
Now there will be no window pop-up. Follow the instructions (playdemo et al) from before.

What this does is that it will produce uncompressed image files in the Portal2 directory for every single frame that the demo replays.
The files are named "yourvideoname0001.tga", "yourvideoname0002.tga" and so on. They will take a LOT of disk space. Say, you are recording at 1920x1080 at 30 FPS, and you are recording a 10 minute movie. This counts as 18000 frames, each of which is 6.2 megabytes long, for a total of about 106 gigabytes.
In addition, it will create a "yourvideoname.wav", which contains the soundtrack of your video.

The good thing about this method is that as long as you don't run out of disk space, it does not matter even if your video is ten hours long.

To deal with the heap of TGA files and the WAV file, you need a dedicated video encoding program. Since there are many of those programs and the programs are rather varied, I will rather refer to this Wiki article about the topic: https://developer.valvesoftware.com/wiki/Demo_Video_Creation#Exporting_to_images_.28jpeg.2C_targa.29_and_.wav_files

Personally, I use MEncoder in Cygwin, using the following commandline:
mencoder -o video.avi -mf fps=30 mf://yourvideoname%04d.tga mf://yourvideoname%05d.tga -ovc x264 -x264encopts crf=7 mencoder -o video2.avi video.avi -audiofile yourvideoname.wav -ovc copy -oac copy
Or (substituting for the second mencoder line):
flac -8 -f yourvideoname.wav mkvmerge -o yourvideoname.mkv --default-duration 0:30fps --aspect-ratio 0:16/9 --compression 0:none --compression 1:none yourvideoname.avi yourvideoname.flac

And also, because I don't really have 100 gigabytes of disk space for the TGA files on my laptop, I use a set of Cygwin scripts to periodically transfer and move them through LAN to another computer (that does) while Portal 2 is running.
But this steers a bit too much on the expert venue, so I will not elaborate it more. Just read the Wiki article. If you can, use the AVI method. It is much simpler.

On the other hand, if you want to post-process your audio, such as add narration / other voice-over or background music, this is the simpler way to go. Just open up the .wav file in e.g. Audacity (http://audacity.sourceforge.net/), do your changes, save, and use the new wav file instead of the old one.
Uploading to YouTube (tm)
Finally you should have an AVI file ready. Just log in to YouTube(tm) using your YouTube(tm) account, and go to http://youtube.com/my_videos_upload and follow the instructions on the screen. Voilá! You have now published a gaming video on YouTube.

Congratulations!
57 Comments
rc2sm Mar 6 @ 10:37pm 
Hint: I think you can record at a higher frame rate to create a slow motion video - for example, use slow motion at certain points to make the video more interesting. Similarly, you can use a third-person view - shoot two videos from different perspectives and then interweave the shots in an external editor.
Bisqwit  [author] Jan 25, 2015 @ 4:53am 
Probably something you chose in the x264 configuration dialog box. Can't know more with the information you provided.
John Goodman (RU) Jan 21, 2015 @ 12:10pm 
--------------------
~sv_cheats 1
~host_framerate 60
~startmovie test

x264vfw [error]: incompatible input/output frame format (encode)

~endmovie
--------------------
test.avi --- 0 kb
--------------------

What am I doing wrong?
arttgog Dec 23, 2014 @ 7:12am 
Thanks dude that will come in so helpful when im making things
Bisqwit  [author] Dec 23, 2014 @ 2:25am 
To take a desktop screenshot use the printscreen button, and to take a window screenshot use alt+printscreen (sysrq). The screenshot will be placed on the system clipboard. Then open e.g. Paint and paste it, and save into a file. Remember to crop the image properly.
arttgog Dec 22, 2014 @ 11:19am 
How do you take pictures of your desktop like that? I asked alot of people but they never EVER respond for some reason
Bisqwit  [author] Oct 29, 2014 @ 12:50am 
I have meant to check out SrcDemo2 for a while. Especially the process of rendering at high framerate and blending sounds very interesting. I have been doing the exact same thing using my own homebrew tools before. However, I have my suspicions that SrcDemo2 might still not work for me.
When I'm running my own script, I have to use pssuspend.exe from SysInternals to suspend the game executable (hl2.exe or portal2.exe) every once in a while, to let the compress/transfer program catch up on the files that the game wrote. Otherwise the game will keep writing TGA files faster than the other process can compress them, and the disk becomes full. I don't see SrcDemo2 possessing the suspending feature, and thus I think it's likely to suffer from the same problem on my computer.
quat Oct 20, 2014 @ 8:39pm 
If you would like to make a long video but are short on disk space, look in to srcdemo². It captures the TGA files before they are written to disk and re-encodes them as much smaller PNG or compressed GIF files. As an added bonus it can add motion blur and stuff (Basically renders at a really high frame rate and blends the pictures together before turning the frame rate down.) The problem is that it's really slow compared to the normal tga methods.

It's easy to use, just make sure you match the folders in Portal 2 and srcdemo².
johndaggett May 21, 2014 @ 6:58pm 
Thanks Bisqwit - I used the AVI method and then uploaded to YouTube. Worked great!
Bisqwit  [author] Mar 5, 2014 @ 8:11am 
Yes, that is supposed to happen. As explained under the chapter "For arbitrary long movies: Using the TGA recording method". If you want it to make an AVI file, you have to include the word "avi" after the movie name, i.e. "startmovie test avi". Note that there is no period (.) in that command.