You are on page 1of 10

How to encode in H264

http://www.wcreplays.com/forums/showthread.php?
t=113891
Guide: How to encode using VirtualDub and x264
and Lame mp3
Introduction:
This guide is in response to diablogod's FPVOD
guide. Basically, Windows Movie Maker sucks for
encoding and the wmv codec is just horrid. x264 and
Lame are two of the most popular video and audio
codecs and are just much better in general: better
quality to speed ratio and quality to filesize ratio. Not
to mention x264 is multithreaded optimized for you
people with quad cores.
Things you will need:
VirtualDub (latest 1.8.8)
http://www.virtualdub.org/
x264 VfW codec (latest r1145)
http://sourceforge.net/projects/x264vfw/
Note: Make sure you get the VfW version of the x264
codec. If you download the .exe version, you'll have
to use it through a command line, which I won't cover

here and is a bit more technical. VfW stands for


Video for Windows. It basically means you can use
VirtualDub instead of the command line.
Lame mp3 codec (dunno what the latest is)
You can get it from where ever but I got mine from
the K Lite Codec pack (latest 4.8.5)
http://www.freecodecs.com/download/...codec_pack.htm
Be sure to download the full version (there's basic,
standard, full), and install it with the setting "Lots of
stuff." -Thanks Splinty
Step 1: Joining your .avi files
So in your fraps folder, chances are you have more
than one file since you're games usually are longer
than 1-2 minutes. Good news is that VirtualDub can
join .avi files. Bad news is that you have to join them
one by one, a bit tedious if you ask me, but hey it's a
free program. It's highly recommended you join your
avi files before you encode (if you're doing 2pass) for
reasons I will discuss later.
So you open up your video with VirtualDub. Then
you drag the bottom slider all the way to the right.
Then you click File -> Append Avi Segment. Then
you open up your next video and repeat. After that

click File -> Save as Avi and save it somewhere and


you're done.

Step 2: Converting the frame rate


Click on Video -> Frame Rate -> check Convert to
fps: -> pick a number
Usually it's 25 or 30fps but I'll leave that up to you to
decide.

Step 3: Setting up the video compressor


Click on Video -> Full processing mode.
This will make sure the video gets encoded and
you're not just making an exact copy of your video
(direct stream copy).
Next click on Video -> Compression
If you setup x264 correctly, the codec will be there.
Mine is listed as x264vfw - H.264/MPEG-4 AVC
codec. Click on it and click Configure.

A box with a load of options will pop up. The first


thing you wanna do it click on the "single pass" drop
down box and select "Multipass - 1st pass."
Doing multipass encoding means that the compressor
looks at the video multiple times so it would better
know when and where in your video it should
allocate a higher or lower bitrate. For example: a
scene with lots of motion and intense action would
require a higher bitrate to look good than a dark
scene with little going on. This is where joining your
videos before encoding comes in. You want the
compressor to be looking at the entire video and not
just 1-2 minutes of it, before deciding when/where ti
allocate bitrates. During the 1st pass, the compressor
skims through the video and makes a note of its
findings in a .stats file. The 2nd pass does the real
encoding and allocates the bitrates properly. You can
also do more than 2 passes, but typically the
difference in quality is almost neglible.
Doing singlepass or 1pass encoding means that the
compressor only looks at the video once. This isn't
too good since the compressor doesn't really know
what scene is going to come next and may allocate
too much or too little bitrate to the scene. Really, the
difference between 1 and 2pass encoding is night and
day. Always do 2pass encoding if you can.

Ok so you have Multipass - 1st pass selected. Next


you'll have to set your bitrate. The higher you set the
bitrate, the higher quality the video, but also the
bigger your final video. I personally set mine at
2000*, unless the game was really short (less than 10
mins), which I set it to 3000 or higher.
/*I used to set at 1000kbps but for a 720p video, it
gives you quite a small filesize. You will have plenty
of leeway for bitrates when it comes time to upload
to Youtube with its 1gb limit.
*/
Next set where the stats file is saved to. You can pick
where ever you want including the default location,
but just be sure you remember where you saved it for
your next pass.

Next click on Analysis & Encoding for a load more


options. I won't go in-depth as to what these options
do, but if you want to perfectly optimize your
settings, you can go here:
http://mewiki.project357.com/wiki/X264_Settings
Default settings are pretty much good enough for
everybody. The main setting you want to be looking
at is the ME algorithm. Starting from the top, dia is

the quickest method of encoding but lowest quality.


Tesa is the slowest method of encoding (basically
brute force), but highest quality. I'm not sure why dia
is even there when hex is far more efficient and is
almost as fast as dia. I personally have this set to tesa
since I can leave my computer on overnight to
encode.

Next click on Rate control & Other for even more


options. The setting to look at here is under
Multithreading. Set Threads to how ever many cores
(or logical cores, if you have hyperthreading) you
have. This makes it so x264 will use all of your
threads and encode faster. Or set it to one less thread
so you can have one thread for gaming or whatever
while encoding, but don't expect to encode fast if you
do. Hit okay and we're done for video settings.
Step 4: Setting up the audio compressor
Click on Audio -> Full processing mode.
Click on Audio -> Compression
On the left side, select Lame MP3
Find the hz of your video. You can do so click on
Audio -> Conversion. At the top left, it'll say "No
change (xxxxxx)" where xxxxxx is your video's hz.
I'm not sure if you can notice a difference, but just

pick the one that matches your video. Next you select
the audio bitrate. A comparison list can be found
here:
http://en.wikipedia.org/wiki/Bit_rat..._in_multimedia
Personally I use 128kbps. Next pick ABR. ABR
stands for Average Bitrate, and is generally better
than CBR (Constant Bitrate). Refer to wikipedia if
you want to learn about it more in-depth. So the
setting you should have (or atleast for me) looks like
"48000 Hz, 128 kbps ABR, Stereo 21KB/s." Press ok
and we're done for audio.

Step 5: Saving the video (1st pass)


Click on File -> Save as AVI
If you only selected 1pass, you're done here and can
start enjoying your video. If you selected 2nd pass,
you'll have to go back to Video -> Compression ->
x264 codec -> configure and select Multipass - Nth
pass (also make sure the stats file location matches
the one from the 1st pass), and then File -> Save as
AVI again. I'm not sure if it's a good or bad idea, but I
always save the 2nd pass to a new file instead of
overwriting the old one. Now you can enjoy your
newly encoded video in higher quality.

Important Note:
If you're encoding a bunch of videos at the same
time, be sure to set new stats locations for each video.
Setting each video to the same location will cause
each video to use the same stats file as the 1st one,
defeating the purpose of the multipass process. Each
following encode will NOT overwrite the stats file
with a new one.
Optional stuff:
Saving your settings so you don't have to repeat this
long process:
Once all your settings are set (for the 1st pass),
including frame rate conversion, video compression,
and audio compression, click on File -> Save
Processing Settings. Next time you want to encode
something, you can click on File -> Load Processing
Settings, and you're all set.
Splitting your final video (after encoding):
click on Video -> Direct stream copy
click on Audio -> Direct stream copy
click on Video -> Select Range

Put 0 in the start box under Time (ms). 10 minutes is


600,000 ms (milliseconds), so now in the length box

under Time (ms), put 600,000. This will make your


video exactly 10 minutes long. When you go to save
it. Saving it should only take a couple seconds unless
you have a really really slow computer, you're saving
a giant file, or you accidentally set it to encode those
10 minutes instead of copy (direct stream copy).

Go back to the Select Range box. Now put 600,000


in the Start box under Time (ms), and put 0 in the
End Offset under Time (ms), and then save as avi.
This will output the rest of the video. If you have a
video that's longer than 20 minutes, you'll have to put
600,000 in the Length box under Time (ms) again
and keep adding 600,000 each time to the Start box
under Time (ms) until you have less than 10 minutes
of video left.
Hex vs. Tesa:
Test was done using an (exactly) 8minute video of a
WC3 game 1280x1024@60fps. Initial filesize was
23.2GB, final size both were 64.9mb +/- 15kb.
Converted to 30fps. Video codec used: x264,
1000kbps 2pass. Audio codec used: Lame mp3,
128kbps 48khz ABR. Encoded on an E6400@3.2ghz.

Hex: http://www.youtube.com/watch?
v=dGxONAiUwm8
pass1: 16 minutes
pass2: 14 minutes
Total: 30 minutes
Tesa: http://www.youtube.com/watch?
v=jl7jF7N5aYc
pass1: 28 minutes
pass2: 27 minutes
Total: 55 minutes
More to come:
entire guide done in hypercam?
more?