Sie sind auf Seite 1von 12

70+ stores to shop

Major stores Everything from A to Z


www.arconlinemall.com
Treyone Collectibles
Antique Collectibles and More! 90 day, 100%
Money Back Guarantee.
Your Ad Here!
BIDVERTISER ADS
Encoding videos using x264 and VirtualDub Encoding videos using x264 and VirtualDub Encoding videos using x264 and VirtualDub Encoding videos using x264 and VirtualDub
February 21, 2006
December 29, 2006: You can temporarily get an older version of x264 for this guide over here:
http://videos.co23.com/x264-440-install.exe.
October 10, 2006: A lot of people at doom9 are no longer provided any kind of support or answers regarding
x264 and VFW (VirtualDub). As such, you can no longer get a "latest build" of x264 VFW which this guide requires.
If I can find some time, I'll provide another guide which utilizes the Command Line Interface x264, MeGUI,
AviSynth, mkv container, and optionally avc2avi. It's harder to explain but once you get it down it makes it much
easier to achieve consistent results.
A lot of people often ask me, "what codec did you use to encode that video?" I usually reply to them with "x264"
and their immediate response is "where can I get that?" If you have never heard of x264 and H.264 or Advanced
Video Coding (AVC), they are the next generation video codec and standard respectively. x264 is a very impressive
codec and can achieve high video quality at low bitrates.
In this guide, I will show you one method to compress video with x264. All of the tools in this guide are free,
open source, and run on Windows. The initial setup time is a little slow and the encoding process is slow as
well, but the quality to file-size ratio is impressive. This guide is not about how to create your own videos,
only how to compress existing computer video (AVI files and the like) to a high quality format.
x264 is still in development, but recent builds have shown that it is already powerful and usable. Unfortunately,
your viewers will need x264 decoder software to play videos. Another drawback is that x264 is much more
processor intensive; much older computers with 1ghz cpus or slower may have trouble decoding x264 videos. Some
less knowledgeable users will be a little frustrated at first, but if they have the hardware and the correct software,
they are typically fairly impressed with the results. If you would like to learn more about x264 visit the videolan
developer website.
The method described in this guide uses the fewest number of tools. On the other hand, it is slower and more
prone to errors and crashes during encoding or batch encoding. The crashes occur because the x264 codec is still in
development and it appears the "Video For Windows" (VFW) style codec has more bugs. VFW and the AVI container
format also have known issues surrounding H.264 and other newer codecs. A VFW codec is the type of codec
VirtualDub uses and is built into Windows. AVI is a container format that is also supported by Windows.
Unfortuntely, both are old and both have flaws that are not intended to be compatible with H.264. With a number
of hacks, however, the AVI container can be used. Fortunately, you do not have to worry about the incompatibilities
for this guide, but it is good to know that they exist. If you want to know the details, visit this doom9 forum thread.
This guide is intended to be a starting point especially for people very new to video encoding. In later guides I will
show other tools that will actually get the job done better than the toolset described in this guide.
Home Home Home Home About About About About Contact Contact Contact Contact
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
1 of 12 11/8/2009 11:28
Required Tools Required Tools Required Tools Required Tools
VirtualDub [VirtualDub homepage]
Open-source video processing tool.
Sharktooth's x264 Standard or Lite Package [doom9 forums]
The open-source H.264 codec.
ffdshow daily build [Sourceforge]
An open-source codec pack for playing x264 encoded files.
(Optional) LameMP3 ACM codec [rarewares.org]
Open-source MP3 audio codec. Necessary for adding compressed MP3 audio to the video.
Instal l i ng Vi rtual Dub Instal l i ng Vi rtual Dub Instal l i ng Vi rtual Dub Instal l i ng Vi rtual Dub
Get a stable release build of Virtualdub at http://virtualdub.sourceforge.net/. There version of Virtualdub
used in this guide is 1.6.10. Other versions of the program close to this version should work as well.
VirtualDub is not packaged with an installer so you will choose where you want the program to reside. Installation
is straight-forward once you understand what's going on:
Extract the contents of the downloaded ZIP file to a location on your computer. 1.
Once complete, you can go to the location where you extracted the files and run VirtualDub.exe to start
the software.
2.
(Optional) For convenience, you may want to create a shortcut to VirtualDub.exe on your desktop or start
menu.
3.
Instal l i ng x264 Instal l i ng x264 Instal l i ng x264 Instal l i ng x264
Get one of Sharktooth's x264 daily builds at the doom9 MPEG-4 AVC forum daily builds thread. You are
interested in either the Lite or Standard package. Choose the Standard package if you are unsure.
The x264 package comes with an installer that will guide you through the installation process. The default settings
should work.
Instal l i ng ffdshow Instal l i ng ffdshow Instal l i ng ffdshow Instal l i ng ffdshow
Get ffdshow from the ffdshow daily builds webpage.
ffdshow comes with an installer as well to guide you through installation. While the defaults will work, I highly
recommend un-checking the Postprocessing video filter and volume normalization audio feature during installation.
Instal l i ng LAME MP3 ACM Codec Instal l i ng LAME MP3 ACM Codec Instal l i ng LAME MP3 ACM Codec Instal l i ng LAME MP3 ACM Codec
Lame MP3 is necessary to add compressed audio to your video. Get the Lame MP3 encoder Bundle from
rarewares.org. To be safe, you probably want to use a beta instead of an alpha.
Extract the files in the ZIP file to a temporary folder on your desktop. Open the folder and right click the
LameACM.inf file and click "Install." A dialog may warn you about installing the software, to continue click "continue
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
2 of 12 11/8/2009 11:28
anyway." You might be prompted to restart before the changes will take effect. Once installed, you can delete the
folder on your desktop.
Encoding Passes, Bitrate, and Reference Frames Encoding Passes, Bitrate, and Reference Frames Encoding Passes, Bitrate, and Reference Frames Encoding Passes, Bitrate, and Reference Frames
Before you begin encoding, you need to educate yourself a little about some common encoding jargon and
methods: encoding passes, bitrate, and reference frames.
Video codecs utilize data they get from prior encoding passes to help determine how to distribute the bits over the
entire video. Bits are the data used to describe the video and bitrate determines how many bits are available for a
period of time. For each pass, the codec will analyze the video as a whole and determine which parts are more
complex than others. On following passes, the codec distributes bits over the entire video utilizing what it saw on
previous passes. For example, if you have less complex scenes with still-shots or very little motion, the codec will
detect that on the first pass. On the second pass it will know that it can take away some data from that scene and
place it on a more complex scene with lots of motion or lots of detail. With single pass the codec does not know
what to expect 1 minute later in the video, so it will guess on how to distribute data over small chunks of the video
it sees at that point in time. With multiple passes, the first pass is generally thrown away and done very quickly
since the codec has no data to work with. Second and third passes are done applying the codec's full capabilities
and produce the final encoded video. x264 is capable of performing three or more passes, however, after the
second pass the benefits start to diminish quickly. If you are really picky, you can see the small differences between
two and three pass encodes. Many experienced encoders will generally say a fourth pass does not provide any
noticeable improvements, but the possibility of doing them is always there.
The bitrate determines how big the final file will be and how much the quality will suffer; the larger the bitrate,
typically the better the video will look. Likewise, as you lower the bitrate, the quality decreases. I recommend
experimenting with a short 30 second clip and do a little bit of math to determine how big your actual video will get
and what bitrate you want. As a reference, if your video file has a resolution of 640x480 and frame rate of around
30 frames per a second then a bitrate of 1000 provide pretty good quality depending on the video contents. There
is no way to tell how good the quality will be until you actually try it. That is why it is a good idea to experiment on
a short clip first before wasting hours of encoding the entire video. For things like cartoon animations you can get
away with fairly low bitrate before the video starts to show noticeable defects. For things like detailed video game
clips or high action scenes, a high bitrate will be necessary. Finally, choose a clip that contains varying amounts of
motion or detail, otherwise you may get a false impression of the bitrate you need.
Another piece of useful information is that many encoders typically encode movie content so they can store the
movie on cheaper media. These users will often try to hit a target file size rather than a target bitrate. For
example, if they have a 700mb capacity cd, they often will use a bitrate calculator to determine what bitrate they
can use to make the file size exactly 700mb. When getting started, I would not worry too much about hitting
specific sizes. Most people reading this probably will want to use this information to compress content that is
distributed over the internet rather than for archive purposes.
The default VFW x264 codec uses a Max Reference Frames value of 1. In this guide, we change this value to 5 in
order to increase the final video quality. Generally, the higher the number of reference frames increases the quality
of the video. Obviously there is a cost to increasing the reference frames: much longer encoding time. If you want
to try playing with this setting, I would go no higher than 15 reference frames. There are many more settings in
x264 and a lot of them are not accessible from the VFW codec. Most of the other default settings are already pretty
good so you do not have to worry about them for now.
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
3 of 12 11/8/2009 11:28
Encoding the Video Encoding the Video Encoding the Video Encoding the Video
Now that you have all the tools installed, you can start playing with the encoding process. For this method, I will go
over two encode methods: single-pass and two-pass. The fastest way to get a result is to use single-pass, but the
quality will definitely be worse than the results of a two-pass encode. Two-pass is the best way to improve the
quality without tweaking with the codec settings. Single-pass is good if you are short on time, do not care about the
resulting file size, and do not mind the quality. Often none of those are true, but it is still useful to know single pass
first before two-pass. I recommend using single pass with a high bitrate to temporarily store uncompressed video.
Si ngl e Pass Si ngl e Pass Si ngl e Pass Si ngl e Pass
Start VirtualDub and open your video file by dragging the AVI to VirtualDub. You should be able to play the video
within Virtualdub by hitting the play button with a small "I" at the bottom left.
Now we need to configure the video encoder settings:
Go to the Video menu and make sure Fast Recompress is selected. 1.
Go back to the Video menu and click Compression. 2.
In the list, click x264 - H264/AVC encoder. 3.
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
4 of 12 11/8/2009 11:28
Now click the configure button. 4.
x264 codec window should show, make sure the drop-down has Single Pass - Bitrate. 5.
Now select your average bitrate value. 6.
To boost the quality, we will change the reference frames value:
Click on the MBs&Frames Tab 7.
For Max Ref. Frames enter a value of 5 8.
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
5 of 12 11/8/2009 11:28
Click ok, and ok again. 9.
Video encoding settings are now ready. 10.
If you have audio along with your video, you will want to compress that as well, if not, you can skip the following
steps.
Click the Audio menu, and make sure Full Processing Mode and Source Audio are selected. 1.
In the Audio menu, click Compression. 2.
Select Lame MP3 in the list 3.
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
6 of 12 11/8/2009 11:28
Select your desired audio bitrate on the right (recommended: 44100 Hz, 128 kbps CBR, Stereo). 4.
Click ok. 5.
Audio encoding settings are now ready. 6.
Now you are ready to begin encoding. Click File then Save as AVI.... Enter the name of the avi encoded file and
click Save.
A VirtualDub progress screen should show up.
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
7 of 12 11/8/2009 11:28
Two Pass Two Pass Two Pass Two Pass
For two pass, we start out just like single pass: Start VirtualDub and open your video file by dragging the AVI to
VirtualDub. I will not repeat duplicate screenshots here so refer to Single Pass if you get confused.
Before we continue, you will be setting a lot of things and sending them to VirtualDub's Job Control. Job Control
(hotkey F4) is basically a list of things VirtualDub will do in sequence. At anytime, you can remove the jobs and
reconfigure them before you do the actual encode in the Job Control window. This is nice to know if you accidently
add a job that you did not want.
Configuring the 1st Pass Configuring the 1st Pass Configuring the 1st Pass Configuring the 1st Pass
These steps are very similar to steps described in 1pass encoding except we change the pass setting in the x264
codec screen and we queue the jobs to job control in the Save as dialog.
Configure the video encoder settings for the first pass:
Go to the Video menu and make sure Fast Recompress is selected. 1.
Go back to the Video menu and click Compression. 2.
In the list, click x264 - H264/AVC encoder. 3.
Now click the configure button. 4.
x264 codec window should show, make sure the drop-down has Multipass - First Pass (fast). 5.
Now select your average bitrate value. 6.
Click on the MBs&Frames Tab 7.
For Max Ref. Frames enter a value of 5 8.
Click ok, and ok again. 9.
First Pass video encoding settings are now ready. 10.
Since this is the first pass, we don't need to do anything with the audio, so we will disable it:
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
8 of 12 11/8/2009 11:28
Click the Audio menu, and select "No Audio." 1.
Now we tell VirtualDub to queue the first pass:
Go to File, and click Save As Avi... 1.
In the dialog, check Don't run this job now; add it to job control... at the bottom. 2.
Enter a file name.
The file name you enter here is not the final video file name; it is just a temporary file for encoding. Enter
something like video_first_pass.avi so you know to delete the file after the pass completes.
3.
Click save 4.
The dialog should disappear and the first pass should be queued in VirtualDub's job control. 5.
Configuring the 2nd Pass Configuring the 2nd Pass Configuring the 2nd Pass Configuring the 2nd Pass
For the second pass we just need to set the codec to the 2nd pass and add our audio compression settings if we
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
9 of 12 11/8/2009 11:28
have audio.
Configure the video settings for the second pass:
Go to the Video menu and click Compression. 1.
In the list, click x264 - H264/AVC encoder. 2.
Now click the configure button. 3.
x264 codec window should show, change the drop-down to Multipass - Nth Pass.
The bitrate you selected in the first pass should still be the same so you do not need to change anything
else.
4.
Click ok, and ok again. 5.
Second Pass video encoding settings are now ready. 6.
If you have audio along with your video, you will want to compress that as well:
Click the Audio menu, and make sure Full Processing Mode and Source Audio are selected. 1.
In the Audio menu, click Compression. 2.
Select Lame MP3 in the list 3.
Select your desired audio bitrate on the right (recommended: 44100 Hz, 128 kbps CBR, Stereo). 4.
Click ok. 5.
Audio encoding settings are now ready. 6.
Now we queue the second pass:
Go to File, and click Save As Avi... 1.
In the dialog, make sure to check Don't run this job now; add it to job control... again. 2.
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
10 of 12 11/8/2009 11:28
Enter a file name.
The file name you enter here is the final video file.
3.
Click save 4.
The dialog should disappear and the first pass should be queued in VirtualDub's job control. 5.
Starting the Queued Jobs Starting the Queued Jobs Starting the Queued Jobs Starting the Queued Jobs
Now we can tell VirtualDub to start the jobs we queued:
Go to File, and click Job Control... 1.
The Job Control window opens, make sure your two entries from earlier are listed. The job names are
automatically assigned by VirtualDub so do not worry if they are not to your liking.
2.
Click the first job 3.
Now click the start button 4.
VirtualDub should now be working and will automatically start the second pass after the first pass completes. Once
both jobs complete, your video will be ready.
Conclusion: Play Your x264 Encoded Video Conclusion: Play Your x264 Encoded Video Conclusion: Play Your x264 Encoded Video Conclusion: Play Your x264 Encoded Video
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
11 of 12 11/8/2009 11:28
x264 Video Playing (actual result not shown; image is highly compressed)
When
the
encoding
process
finishes,
you can
play the
AVI file
you
saved
and
delete
the stats
files.
This is
where
ffdshow
will be
used.
Double-click the file and your media player should start playing the video. While the video is playing, a small
ffdshow icon should appear in your system tray next to your clock. Right-clicking the ffdshow icon will give you
some options. If you forgot to turn off postprocessing during the install, you can turn it off here while the video is
playing.
Hopefully you took my advice and worked with a short 30 second clip. Depending on your bitrate, the resulting
video will turn out worse than you would like or perhaps it turned out better but the file size is still a little big. With
some quick math you can determine how big a full length file would be. I would keep playing with the bitrate until
you hit the point where you are satisfied with the quality to file-size ratio.
The encoding process is generally slow. The biggest external factors affecting encoding speed are: CPU speed,
video resolution, and video length. Encoding speed also depends on the codec settings. The number of settings in
x264 constitutes writing a another guide so I will not cover them here. A good place to look for more information is
the doom9 AVC forums. In a following guide, I will show you how to utilize a tool called MeGUI to make the
encoding process a little simpler and help you get much better results without becoming an x264 expert.
Home About Contact
2006 Rhomel Chinsio
teek.info - Encoding videos using x264 and VirtualDub http://teek.info/guides/video/x264encode.html
12 of 12 11/8/2009 11:28

Das könnte Ihnen auch gefallen