How to Encode High Quality Video From PC-Game Footage

I posted this guide a year or so ago however a lot has changed since then so I am re-writing sections of it an re-posting it here.

So, you’ve seen all those fancy game videos on YouTube, downloaded WoW videos or other MMO gameplay and enjoyed the high quality ones? Well you can do it too!

I am going to provide a step by step guide for creating high quality, full screen resolution (1680×1050 and above is very possible, although half size should be used on slower computers) videos of any game you wish to apply this guide to really. It is highly recommended to apply this guide to decently powerful systems of a dual core or more.

We will be using MeGui as our main encoding UI and x264 as our codec. AAC will be used for sound. First of all, you will need the following:

  • Sony Vegas (optional but very recommended however any video editor will do, except Movie Maker)

 

Order of Installation

  1. Fraps
  2. AVISynth
  3. Video Editor of choice
  4. Lagarith Lossless Video Codec
  5. MeGui
  6. NeroAACEnc
  7. AvsP

First Steps: Setting Up

The first things you should do after you download and install all this software is to setup Fraps the way you want it. For most games, it is now very possible to record at full screen with sound at 30fps, with no lag, on a decently powerful computer (Quad Core or above). These are also the suggested settings. Make sure, if possible, that your recording directory is on a different PHYSICAL Hard Disc than the game (make sure you defrag your FRAPS drive often, it really helps). This allows for much smoother gameplay while recording. Recording at Half Size is also decent, if you have a weaker machine and it will speed up encoding somewhat because you can choose lower quality settings but will, obviously, look worse than full screen videos.

Then, open your task manager, right click on fraps.exe and click on “Set Affinity”. Make sure that Fraps is running on at least 2 cores (or 4 if you have an i7), as shown in the following screenshot. Once you start your game, alt+tab out of it and, if you have a quad core, set it to run on the two (or four) cores that Fraps is NOT running on. Otherwise it should already be running on both cores most of the time. This way you get no interference and both  the game and FRAPS can run at maximum efficiency. For thew newest games however this may cause a slowdown for the game. On really powerful machines this step can be generally ignored.

 

How to make sure FRAPS is running on multiple cores.

Now that we have Fraps all set up, let us take a look at MeGui. It comes with a load of different codecs for both video and sound. The first thing you should do when you run it is update (Options -> Update). This will download the newest version of all codecs as well as MeGui core files. Next, you need to add NeroAACEnc to the list of encoders for MeGui so we can encode the game sound. You should generally keep the game sound in case you want to keep it in your video, however if you are planning on putting music over your recording anyway not recording the sounds increases the in-game performance quite a bit.  Go to Options -> Settings -> Audio and search for where you installed NeroAACEnc. That is it for now, you can close MeGui.

Time to Snip: Editing and Preparing for Encoding

Now that we have MeGui and all the codecs set up, it is time to edit and encode our video. First of all, if you do NOT want to edit the video and simply encode it, skip down to the next step. If you are going to use the file for streaming, see the end of this section.

This part is really simple. After editing your video to your liking, putting in audio and effects, save your project and head to render. Make sure you select AVI as your file type. As a codec choose Lagarith Lossless Video Codec. Go into the codec configuration and check “Enable Null Frames”, “Use Multithreading” and select “YV12″ as your mode. For audio, makre sure you select the “PCM Uncompressed” codec with 44,100Hz and 16 bit depth. Go ahead and render the file now. This might take a while so go grab a snack or something.

 

Now, if you are planning to simply upload the video to a streaming site like YouTube or use it for any kind of streaming only, you can skip a lot of the work below and do something else instead.

Because the streaming sites now support enormous files (2GB+) the careful encoding using MeGui might not be needed and you can take a much faster way out. Simply encode using the Sony AVC (or whatever other h.264 codex your video editor supports) with the following settings:

Audio: 192 Kbps, 48,000 Hz, 32 Bit, Stereo, AAC
Video: 45 fps (same FPS as you recorded in FRAPS), 1920×1080 (whatever resolution your recorded video is in) Progressive, YUV, 15 Mbps
Pixel Aspect Ratio: 1.000

This ensures that there is absolutely no quality loss even in high detail games, however this is not viable if you want your videos to be downloaded and viewed as any decently long videos would be much too large. With these settings a 7:30min long movie is roughly 830MB in size. A 15 minutes video would be roughly 1.6GB which is well below most upload limits. If you need to fit a longer video you can reduce the bitrate to 10mBit and not lose too much quality.

Now, before you actually encode the video you want to add some color correction. FRAPS records in RGB and converting it to YUV12 forces the video to lose some contrast. In Sony Vegas click on Tools -> Video -> Track FX -> Color Corrector. In this screen increase the Saturation up. How much depends on what the actual footage looks like and it is up to your discretion.

Getting the Footage Ready: AVISynth for Dummies

Now, MeGui can’t take AVI files directly, so you are going to have to feed it an AviSynth script. Since you have now installed AviSynth (if not do it NOW), you can right click anywhere and create a “New AviSynth Script”. Name the script whatever you want and then open it with notepad.

AviSynth is a very powerful tool, but we will only be using simple functions, like adding video. For this, you need to enter the following code into the script and save:

#AddVideo
AVISource(“H:\Name of File.avi”) + AVISource(“H:\Name of File2.avi”)
ConvertToYV12()

As an exmaple, this takes lets say two fraps videos ond drive H and puts them together so MeGui can render them as one movie. If you have edited your movie with an editor and saved it using the lossless codec then you can skip the “ConvertToYV12()” line. You can also add as many files together as you want using the syntax above, but keep in mind that you should plan on the encoding taking about 2-3 minutes for each minute of footage.

Now on to color correction. FRAPS records in RGB and converting it to YUV12 forces the video to lose some contrast. To do this start up AvsP and open the .avs file you created earlier. Add the following below ConvertToYV12():

TWEAK([<"hue", -180.0, 180.0, 0.0>],[<"sat", 0.0, 10.0, 1.5>],[<"bright", -255.0, 255.0, 0.0>],[<"cont", 0.0, 10.0, 1.1>])

Now click on the following two buttons to access the menu you just created:

Depending on the footage you will want to increase the Hue and the Saturation to an agreeable level. Save your script.

 

Now, go ahead and start MeGUi. You will see an “AviSynth” line. Search for the script you created and open it. A preview window should open and show you the exact middle of your video. Your files are now loaded into MeGui and are ready to be encoded. Give it a name in the “Video Output” and select the appropriate x264 codec (see section below) and then MP4 as the file format.

Further AviSynth syntax can be found here and here.

The Encoding: Trial, Error and Lots of Time

So, you made it this far. That was the easy bit. Now comes the hard part, encoding the video with a decent quality! Depending on if you recorded full screen or half size will matter greatly here.

Make sure to select x264: *scratchpad* so you can setup your encoding then click the Configure button. There are a TON of different settings in the x264 configuration, however I am going to explain the most important ones only. If you want to see ALL the different settings and what they do, take a look here.

 

Presets

You can safely ignore these. Any changes you make will be applied instead of these.

 

Bitrate

The bitrate is the general quality measure of your video. For good computer game encodes, in full screen resolutions, you will want a bit rate from 3000-6000. Keep in mind that the higher the bitrate, the higher the filesize will be. You can save space with the right compression settings, but higher bitrate will always make bigger files with the same settings.

Mode

You will generally only want to use “Automatic 2Pass”. This means that the encoder will work over the file twice. The first time it will analyze it in order to be able to save as many bits as possible in scenes with little movement or action. This way you save a lot of space with no real loss to quality.

Constant quality will make sure all the scenes use the same bitrate, however this means a lot of wasted space. Not the best setting for computer game recordings.

1Pass Encoding is not really recommended either, as it means that the file will only be looked over once, foregoing the bonuses of either constant quality or 2Pass. Do not use.

De-Blocking and CABAC

This is a very important setting, especially when dealing with electronic video. There is no reason to disable this as it provides a substantial quality boost to the video. There are two settings for deblocking: “Deblocking Strength” and “Deblocking Threshold”. Strength determines how strongly a blocky part of the image can be modified. The higher it is, the stronger blocks will be smoothed, but this means that details surrounding blockyness will be smudged. Threshold is the power with which the encoder decides what is blocking and what is actual detail. The stronger it is, the more aggressive the search will be but the more details will be lost because the encoder will not be sure what is blockyness and what is details. The standard setting for this is 0:0, however for perfect quality material (full screen screen capture for example) you will want to use something like -1:-1 (or more) in order to preserve the details of the video. However, if you have recorded in half size, you will want to have something a little stronger along the lines of 1:2 or 1:1. These are just examples however, it varies from video to video.

 

 

Screenshot from original material.

SWGEmu with strong deblocking. You can see details becoming smudged.

 

High quality encoding with weak deblock. Details are saved and the good encoding helps to remove artifacts.

This is WAR with weak De-Blocking.

This is WAR with strong De-Blocking. As you can see, de-blocking strength is dependent on the game. While in SWGEmu higher de-blocking causes loss of detail and smudging, in WAR, it provides good quality. It really depends on the picture composition of the game you are playing. If you are playing a game with a lot of minute details and thin lines you might want to opt for a higher bitrate/other settings and lower deblocking (even in the negative range) in order to preserve quality.

As for CABAC, keep it enabled at all times.

M.E Algoritm and Subpixel Refinement

This defines motion vector quality. For the M.E Algorithm “Multi Hex” is generally enough for good quality, but Exhaustive or SATD Exhaustive can be used for high resolution video for quality improvement, but really shouldn’t. SATD is extremely slow and I suggest Exhaustive as the highest you should go, however rarely.

The Subpixel Refinement should generally stay at “10 – QP-RD” unless encoding time is really an issue as it provides good quality improvement, however slows down the encode.

Keyframe Interval and Min. GOP Size

This varies from video to video according to its framerate. A video with 30fps should have a minimum GOP size of 30 and a keyframe interval of 300. A 60fps video should have 60 minimum and 600 maximum etc.

Number of Reference Frames

This setting determines how many frames can be referenced by P and B frames. In other words, the higher this is, the better the quality will be because of more reference material, but the encode will slow down with each one. About 5-7 reference frames should work well for most video.  The P-Frame Weighted Prediction should be set to “Smart”. Encode Interlace and Pulldown should be OFF.

One thing to note is the I-Frames. The higher the number here, the slightly larger the file will be but the more sensitive the encoder will be to scene changes. This means that in games that have a lot of movement such as FPS a higher number should be used as opposed to say an RTS. About 60-80 is good for an FPS, and roughly 40 should be enough for lower movement games. However it is dependent on the game itself so you will have to experiment and see what works best for your footage.

B Frames

B Frames are highly compressed frames that can increase the general quality of a video by storing quality information very effeciently. About 4-5 B frames should be sufficient for very high quality encoding.

You should keep Weighted Prediction for B-Frames checked, Adaptive B-Frame should be set to “2-Optimal” and the B-Pyramid should be on normal.

Macorblocks and Extra

Make sure to have ALL macroblocks enabled for the best quality.

MV Prediction Mode should be set to “Auto” and Trellis should be set to “2-Always“.

Make sure No DCT Decimation and No Fast P Skip are checked. Any other checked options will decrease quality.

Encoding it at last!

Now that you have set up the video encode, go ahead and que it. Do not start the que yet however. We still need to encode the sounds! That’s right. Unlike conventional encoders MeGui takes video and audio separately. We will need to combine them as the final step.

Now, go ahead and open the SAME AviSynth script you made for the video in the audio tab. Set it to use the Nero AAC codec with whatever settings you want for your sound. Go ahead and que this too. You can go ahead and start the que now go eat lunch, take a nap, whatever. Assume 2-4 minutes of encoding for every minute of footage, at the least.

WARNING: Make sure the output file for your VIDEO and your AUDIO are different! MeGui does NOT check this and WILL overwrite one with the other.

Combining It All

Now that you are done encoding both video and sound you are ready to combine the two into your final video! In MeGui go to Tools -> Muxer -> MP4 Muxer. Set your encoded video and audio and make sure the “No Splitting” option as well as the “Standard” device is selected. Set your final video name and go ahead and que it then start the que.

Congratulations! You have now created a high quality video of a good size! It is ready to upload and share. For downloadable videos I suggest using FileFront, FilePlanet or some and is relatively fast for DL.

There are many codecs that have been used for this in the past, especially XVID, however I would not suggest Generally  Xvid has created larger files than x.264 and much worse quality. The footage is 1.5 minutes long and is 33MB in x.264 and 40MB in XVID. This means a 25 minute video would be 550MB in x.264 and 666MB in XVID.

Recommended Players

There are two players that I recommend for playing back such videos: VLC and MPC: HC. MPC:HC seems to take better to high bitrate encodes. I suggest following this guide for enabling VMR9 in MPC.

Enjoy!

http://avisynth.org/qwerpoi/Download.html
Be Sociable, Share!

Comment Pages

There are 7 Comments to "How to Encode High Quality Video From PC-Game Footage"

Write a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>