Encoding DVDs to High Quality Movie Files with XviD

Encoding DVDs to High Quality Movie Files with XviD
and AC3 (http://www.bobsomers.com/articles/dvd-xvid-ac3/1/)
Table of Contents
Introduction And Quality Samples
What You’re Going To Need
Rip Your VOBs And Index Your Movie
Set Up The Frameserver And Fix The Aspect Ratio
Setting Up XviD’s First Pass
Setting Up XviD’s Second Pass
Change Log
There were some errors in the original tutorial as well as some important steps I left
out. These have since been fixed and updated in the full text of the article. For a list of
what I changed, fixed, and added, please see the change log.
The Problem I Was Trying To Solve
I played with DivX for hours on end. I tinkered with FLAC audio. I got sick and tired of
playing around with settings, encoding video for hours, only to achieve sub-par results. I
wanted a way to copy a movie file off the disc and onto my hard drive in at
decent enough quality to not need the disc while keeping the file size reasonable under
control. Some will debate that I did not keep the file size under control but I think I did
for a video file worthy of replacing the disc. Finally, I wanted to do it will all freely
available tools and utilities, codecs and all.
What’s The Skinny On Encoding Time, Quality, Etc.
Total encoding time from start to finish with VirtualDubMod was 7 hours and 6 minutes
for a 2 hour 10 minute movie, with roughly a 2 hour first pass and a 5 hour second pass.
The system I encoded it on is running a Pentium 4 2.4C GHz processor with 512 MB of
DDR 400 RAM. Your results may very based on your system specifications but it’s safe
to expect roughtly 2.5x to 3.5x the length of your movie for encoding. Why so long?
Because the quality’s dang good. Let it run overnight if the time is a problem for you.
Here are a few frame captures from my test project. As you can see, XviD did a fantastic
job with no visible artifacts and great color grading. Take special note of the fact that
dark colors like blacks and smooth transitions of colors don’t look blocky and pixelated
at all.
The final file’s resolution is 720×306 (removed letterboxing and corrected aspect ratio to
2.35, will explain later) and looks excellent when maximized and playing full screen. I’ve
tested full screen playback on both 1024×768 and 1280×800 resolutions and it looks very
However, this amazing quality comes at a price, and that price is filesize. The 2 hour 10
minute movie clocks in at 1.79 GB as reported by Windows. This was quite a bit larger
than my initial target of 1 GB, but after discovering the benefits of the higher quality I am
OK with the extra size. Given the rapidly increasing size of hard drives these days
anyway, getting a movie under 2 gigs isn’t too bad space-wise. Overall, the movie went
from 4.89 GB in VOB files down to 1.79 GB in XviD, 36.6% of its original size while
retaining virtually all of the quality of the original.
What You’re Going To Need
This tutorial assumes you have all of the following installed and in working order. Any
questions about these projects should be forwarded to their respective authors or
contributors, not me. If for some reason these links are broken, check for more updated
versions of these programs at VideoHelp.com, which is one of the best resource sites I’ve
ever found when it comes to computer video.
XviD Codec
Grab the latest XviD codec binary.
This handles the playback of the AC3 audio that we’re going to mux into the final
movie file.
DVD Decrypter
Rips the necessary VOB files off the DVD disc. Especially useful for encrypted
discs and content.
This tool will take the unencrypted VOB files and create an indexed D2V project
file. It also outputs your AC3 audio stream in the process.
VFAPI Reader
This tool is used in conjuction with DGIndex to frameserve the MPEG content in
your VOB files to VirtualDubMod for encoding.
AC3 Delay Corrector and GfaWin32.ocx
If your AC3 files end up with small delays this utility will fix the delays to
maintain your audio/video sync. Make sure you also download GfaWin32.ocx and
put it in the same directory as your AC3 Delay Corrector files or the program will
You’ll need this app to do the actual encoding. We’ll also fix some aspect ratio
and letterboxing issues and mux in the AC3 audio with this tool.
Rip Your VOBs
I’m not going to spend too much time discussing the whole process of using DVD
Decrypter to rip off your VOB files because there are plenty of guides that cover the
process just fine. Instead, here’s the quick instructions to get you moving along.
Put the DVD in your drive and fire up DVD Decrypter. Make sure you’re operating in
IFO mode, not File mode. You can change this by going to the Mode menu and choosing
Next go to the Edit menu and click Select Main Movie PGC. This will select the longest
program chain on the DVD, which is presumably the movie itself. If the duration looks
right on the Input tab than it’s probably the right program chain. Make sure that all of
your chapters are selected and that you set the output directory and click the big decrypt
button. This process could take anywhere from a few minutes to up to an hour depending
on the size of the files and the speed of your computer and DVD drive. Once finished,
however, you’ll have a set of numbered VOBs on your hard drive that are ready to be
Index Your Movie And Grab Your AC3 Audio
Load up DGIndex, which is going to do double duty and index our VOB files for
frameserving as well as output our AC3 audio file for muxing back in later. Go to Open
under the File menu and select all your VOBs and click Open.
You should then be bombarded with a file listing of all the VOBs you just selected. Make
sure they’re all there and that they are in numerical order. Once correct, click OK.
Now select Preview from the File menu. The movie should start playing and DGIndex
will open up a status window displaying the information it’s collecting. Let the preview
run for about 5 minutes to ensure that it gathers enough information.
In the screens above you can see both the preview video and the statistics window. As is
quite apparent in the preview video, there is a huge aspect ratio problem in the source
video. Why is it stretched like that? DGIndex is interpreting it as 16:9 widescreen, when
in reality most movies are shot in a wider aspect ratio such as 2.35:1 or 1.85:1. This isn’t
a problem, in fact we’ll capitalize on this later when we set up VirtualDubMod to encode.
Now take a look at the statistics window. As you can see, the movie was interpreted as
16:9. Again, that’s OK, we’ll fix it later. More importantly, look at what’s displayed in
the Video Type box. It it says Film, you’ll need to perform an additional step before we
output the indexed D2V file. If you’re encoding a movie that was released in theaters,
chances are it will be film. Close the statistics window.
Let’s set up DGIndex to demux our AC3 audio for us. Go to the Audio menu, choose
Output Method, and select Demux Tracks. When we save our project, the AC3 audio
track selected in the Audio > Track Number menu will be dumped to an AC3 file for us.
In most cases, the standard English audio track is track number 1, but if you want
something else make sure to verify which track number it is and select the appropriate
one. You could also select Demux All Tracks from the Output Method menu and listen to
them later to find the right one.
Now if the statistics window reported that your video type was Film, go to the Video
menu, choose Field Operation, and select Forced Film. This will force our output to be at
23.976 frames per second, which is the correct framerate for movies.
Fixing aspect ratios isn’t that big of a deal, but screwing up framerates can be a royal
pain, especially if you ever have any hope of getting your audio and video synchronized.
However, the movie I encoded has perfect audio/video sync and that’s what we’re going
Finally, select File > Save Project to save your D2V file. I like to name it something
informative, like “NameOfMovie.d2v” but it’s completely up to you. Your AC3 file (or
files, if you selected Demux All Tracks) will also be dumped in this directory.
Once it’s finished indexing, which should only take a few minutes, shut down DGIndex.
Fixing Delays In Your AC3 Audio
Check out the filename of the AC3 file that DGIndex dumped out for you. If it states a
delay (anything other than “DELAY 0ms”) we need to fix this delay to maintain the
audio/video sync of our final movie file. Thanks to AC3 Delay Corrector, this is a fairly
simple processes. Load up AC3 Delay Corrector. If the program crashes right away, you
need to get a hold of the GfaWin32.ocx file and put it in the same directory as your AC3
Delay Corrector files. The link to download GfaWin32.ocx can be found on the “What
You’re Going To Need” page.
Next to the Source File box click the button with three dots. Locate your desired AC3 file
and open it. AC3 Delay Corrector is smart and automatically interprets the delay in the
filename and sets all the options for you. All that’s left to do is click the Write button.
When it’s finished writing it will haved dumped a delay corrected AC3 file in the same
directory with “_fix” appended to the filename. Close AC3 Delay Corrector and use the
new AC3 file from here on out.
Building The Frameserver with VFAPI Reader
Congratulations, this is the easiest part of this entire tutorial! Fire up VFAPI Reader.
Click the Add File button and select your D2V project. Another screen will pop up asking
you where you would like to save the AVI file. Pick a location and a name, leave the
other options alone, and click OK.
Now just click the Convert button. We’ve now got an AVI file that will frameserve the
MPEG data from the VOB files ready for encoding and an AC3 audio track ready for
muxing. Close VFAPI Reader and move on to VirtualDubMod.
Removing Letterboxing And Fixing The Aspect Ratio
Go to the File menu, choose Open Video File, and select the AVI file that VFAPI Reader
just created. You should be able to scrub through the video by dragging the slider at the
bottom of the window.
What is letterboxing? If you’ve ever watched a widescreen movie you’ve seen it.
Basically, it’s the use of those black bars above and below the image to show the movie
correctly. Why don’t we want the movie to retain it’s letterboxing when we encode it?
Well, there’s really no reason to keep it. Media players on computers can handle video
files of any resolution, so why not make our movie a size that exactly fits the video data?
Not only that, but if you include the black bars in the video file they’re going to be
wasting some our precious bitrate to store their information.
Instead, we can chop off those black bars and use all of our bitrate on the video, which is
the important part anyway. Another added benefit is that when you play it back in a
media player you get the darkest black your monitor can display on either side of the
video, not the washed out “bright” black of a compressed video file.
To set up this cropping go to the Video menu in VirtualDubMod and select Filters.
VirtualDubMod has a list of built in filters you can use to modify the output it produces.
You can see the cropping button in the bottom right hand corner, but it’s not enabled yet.
Click the Add button, choose the Null Transform filter, and click OK to return to the
filters window.
Now click the cropping button to adjust our cropping settings. Scrub to a frame of your
movie where the edges of the video are pretty well defined. Drag the tops and bottoms of
the image down until they get pretty close to the edge of the image and then use the up
and down arrows in the Y1 Offset and Y2 Offset boxes for pixel-perfect control. Make
sure that both the Y1 Offset and Y2 Offset values are even numbers. You may need to
cheat the actual boundry a little bit to do this but it’s better to cut off a line of image than
it is to leave a line of black bar. Finally click OK.
You won’t see the cropping in the list of filters, but it’s important to note that the
cropping will take place before any other filters we use.
Next we need to apply a resize filter to fix that pesky aspect ratio problem. Click the Add
button in the filters window again and add a resize filter. When you click OK you’ll be
presented with an options dialog that let’s you set the new video size. Now here’s where
a little bit of math comes into play. To keep the highest resolution possible, we want to
retain our 720 pixel width. We just want to “squash” the video into the correct aspect
What you need to do is divide 720 by the desired aspect ratio to get the correct height for
our new video. You’ll need to look on the back of the DVD box to find what aspect ratio
it was shot in. Some common ratios include 2.35:1, 1.85:1, 16:9, and 4:3. To simplify the
math, here’s a basic table that provides the width and height values for different aspect
Common Aspect Ratio Real Aspect Ratio Video Frame Size
Please note that with the 4:3 aspect ratio we can acheive the greatest quality by changing
our width, not the height.
Type in your new width and height values in their respective boxes on the resize filter
options screen. Under filter mode I prefer Lanczos3 for the highest quality but feel free to
choose something else if you like. Do not check the Interlaced checkbox and especially
do not check the Expand Frame And Letterbox Image checkbox, because that would
undo all the work we’re doing right now. Finally, click the Show Preview button. Scrub
through your video and make sure that it looks right and that you chopped off all the
necessary black bars earlier. This is what our output video file will look like. If it looks
good to you, close the preview window and click OK on the resize options screen to
return to the filter list. Click OK to close the filter list.
Setting Up XviD’s First Pass
Here comes the complicated parts. We need to set up VirtualDubMod to run two projects
in batch processing mode. The first project it runs will the be the first pass by the XviD
encoder, which won’t actually output anything. Instead it will collect information about
each frame to give you higher quality results when it actually encodes on the second pass.
Go to the Video menu and make sure that Full Processing Mode is selected. Next, go to
the Video menu and select Compression. This will bring us to the the screen that allows
us to configure our encoder options. Select the XviD MPEG-4 Codec from the list on the
left and click the Configure button.
Now we need to configure the encoder for it’s first pass. Use the following settings.
Profile @ Level
AS @ L5
Encoding Type Twopass - 1st Pass
If there are any zones defined in the Zones box, select and apply the following settings to
each one.
Start Frame #
Rate Control
Weight 0.00
Begin With Keyframe
Greyscale Encoding
Unchecked (unless your video isn’t in color)
Chroma Optimizer Enabled
BVOP Sensitivity
Now click on the Advanced Options button. Use the following settings on the Motion tab.
Motion Search Precision
6 - Ultra High (reduce for smaller files)
VHQ Mode
4 - Wide Search (reduce for smaller files)
Use Chroma Motion
Frame Drop Ratio
Maximum I-Frame
240 if you needed to select Forced Film in DGIndex, otherwise
set to 300
Cartoon Mode
Unchecked (unless you’re encoding something like anime)
Use the following settings on the quantization tab.
Min I-Frame Quantizer
Max I-Frame Quantizer
Min P-Frame Quantizer
Max P-Frame Quantizer
Min B-Frame Quantizer
Max B-Frame Quantizer
Trellis Quantization
Finally, on the Debug tab use the following settings.
Automatically Detect Optimizations
FourCC Used
OutputDebugString Debug Level
Print Debug Info On Each Frame
Display Encoding Status
Now click OK to close the advanced options window and click OK to close the XviD
configuration window. Lastly, click OK to close the video compression window.
Go to the File menu and choose Save As. Make sure the file type is Audio-Video
Interleave (*.avi) and give it a file name. Most importantly, check the box that says
“Don’t run this job now; add it to job control so I can run it in batch mode.” Click the
Save button. That’s it for the first pass.
Setting Up XviD’s Second Pass
Don’t close VirtualDubMod or reopen the file or anything. Just go back to the Video
menu and select Compression again. Click Configure to open the encoder options
window. I’m only going to give you the settings you need to change. Leave everything
else the way it was before.
Encoding Type Twopass - 2nd Pass
For high quality video like the one in the screenshots, toggle the Target Bitrate/Target
Size button to Target Bitrate. Type 1500 in the box to its right. That’ll give the video a
bitrate of 1500 kbps which produces excellent quality video.
If you want to aim for a particular file size toggle the button to Target Size and click the
Calc button to open the bitrate calculator. Type in your target size (in kilobytes) and leave
the subtitles box at 0. Make sure the Container Format is set to AVI-OpenDML. Type in
your movie’s duration. If you checked Forced Film in DGIndex select 23.976 (FILM), if
not select 29.97 (NTSC). Select AC3 as your audio format and choose the average bitrate
of your AC3 audio file. This can be found by looking in the file name of the AC3 file we
outputted earlier using DGIndex. Finally, click OK to close the bitrate calculator.
Remember, only perform these steps if you’re aiming for a particular file size.
Click OK to close the XviD options window and click OK to close the video compression
window. Now we’ve got to add our AC3 audio to be muxed in on the second pass. Go to
the Steams menu and select Stream List. Click the Add button and select your AC3 audio
file from earlier. After a short pause as VirtualDubMod parses the AC3 audio, it should
show up in the stream list. Click OK to close the stream list box.
Go back to the File menu and select Save As. Type in the same name you did before
(taking care to select the AVI file type) and again check the “Don’t run this job now”
box. Click Save to close the window. Now open the job control box by going to the File
menu and selecting Job Control. Both the first pass job from earlier and the second pass
job we just configured should be listed. Your box will differ from the screenshot below
because I’ve already finished encoding. Just click the Start button and VirtualDubMod
will start the long and arduous process of encoding your movie. This would be a good
time to go and do something else for… quite a while. Once the project starts running you
can open a status window from the main VirtualDubMod window that will display its
progress and let you play with the priority settings.
After it’s done you will have your beautiful new high-quality XviD movie file with AC3
audio. Good luck!
After originally writing the article I realized there were a couple of errors with it. Thus,
I’ve added this change log to document whenever I fix or update something in the article.
September 20, 2005
XviD will not encode videos with an odd-numbered height. For example, when
encoding a 1.85 aspect ratio movie at the previously stated size of 720×389 it will
crash out with an error message. All XviD files must have an even height. The
correct frame dimensions have been updated.
Added AC3 Delay Corrector (and its associated GfaWin32.ocx) to the required
tools list with download links.
Added instructions on using AC3 Delay Corrector to fix delays in the AC3 audio
stream dumped out by DGIndex. These new instructions can be found on the
same page as indexing your movie with DGIndex.
Download PDF
Similar pages