If geeks love it, we’re on it

Ripping DVD to XViD: Ultimate guide 2.0

Ripping DVD to XViD: Ultimate guide 2.0

Preliminary Legal Disclaimer:


This document does not promote, condone, or otherwise legitimize piracy. All
source Digital Video Discs (DVDs) used to portray the conversion of
MPEG2 (� Motion Picture Expert Group) have been legally purchased from
licensed and authorized retailers of multimedia and electronics. The author
(Robert “Thrax” Hallock) and the location of this tutorial’s
hosting (www.Short-Media.com) take no responsibility for the misuse
of this guide, nor are they responsible in legal or non-legal capacities for any penalties/punishments/investigations incurred. Furthermore, no part of this
guide is eligible for reproduction without the express and documented consent
of the author. Following this guide, or any line therein signifies that you
have agreed to these terms and are operating within the defined parameters thereof.
Failure to abide by its terms indicates your agreement to incur any penalties applicable in accordance with city/county/federal/state laws. This tutorial is copyrighted under the WIPO Copyright Treaties of 2002, and belongs to its
original author. All software and codecs depicted in this guide are free of
use and licensed under the GPL licensing scheme.

Introduction

This is version 2.0 of the DVD2XViD document I authored on 08/26/2003.
Between August and July of this year (2004), there have been considerable improvements
in both software and codecs. DiVX is bordering on the magical v6.0, and XViD
is finally a stable non-beta codec at version 1.0.1. In addition to the development
of codecs, several new and exciting pieces of encoding software have matured
or debuted to the point where they are essential and powerful tools for encoding.
This version of the DVD2XViD document hopes to detail these improvements so
you can successfully encode your DVDs into the exciting, compact, and portable
format of XViD.

The last guide focused on getting acceptably high quality as quickly as possible.
Using DVDx and few other external tools, the result was a decent replica with
MP3 audio. In light of the new and exciting tools mentioned above, this article
is divided into three distinct portions:

  1. Beginner/Quick: Uses AutoGK
    to automate all the processes of XViD encoding including resizing, cropping,
    quantization matrixes, frame rate conversion, and audio muxing all from a single
    interface. Set and forget encoding.
  2. Intermediate: Uses Gordian Knot to automate the processes
    of XViD encoding. This program offers more detailed control than AutoGK, however
    it requires significantly more user input. The result is better quality in exchange
    for a sharper learning curve.
  3. Advanced: Using AVISynth and VirtualDubMod, this section
    of the tutorial focuses on teaching you the frame serving language of AVISynth
    and how to maximize your encoding potential. This section includes detailed
    descriptions on post-processing, video restoration and otherwise making the
    best of your encode. AVISynth and VirtualDubMod is the most powerful combination
    on the planet for encoding procedures, but it’s also mind-numbingly difficult
    to master.

Regardless in which portion you invest your time, the quality of your final
product will be superb.

In addition to separating encoding difficulties
into three separate levels, this guide focuses on a marked expansion in MPEG4
and XViD explanation so you can begin to understand how to control the codec
for yourself, for your own needs. And lastly, this guide features the introduction
of the aforementioned software and codecs:

  • AC3 Audio – High quality Dolby Digital 5.1 audio streams.
  • XViD 1.0.1 – Improving on a solid reputation, XViD 1.0.x
    introduces higher speeds and more precise control at the codec level.
  • Matroska – A new container format. Container formats are
    the actual file structure which contains your encoded product. Different containers
    have different features. Matroska is brand new and supports DVD-like menus,
    chapters, and a whole slew of audio and subtitle options.
  • OGM – Another new container format. This one allows the muxing
    of OGG audio files with MPEG4 streams, as well as a host of other features.
  • Subtitles – Employing VobSub, you can now enjoy the possibility
    of having subtitles in your XViD encodes. Foreign languages with subs? No problem.

If I added things, that means things have also
been removed:

  • No more DVDx – Requires more input than AutoGK, but
    has worsened results. It’s outta there.
  • MP3 Audio – Reduced the focus on this audio format,
    as this guide focuses on 2CD rips which begs for AC3. But as instructions for
    1CD rips are included, it will be given a mention.
  • Slow Log Analyzing – With DVDx the log from the first
    pass of the encoding section took forever, up to an hour or more. That
    will not happen in this guide.
    Logs should be quick.

What is XViD?


XViD is a video encoder/decoder (CoDec) that
operates under the MPEG-4 Part 2/ISO #14496-2 standard. Using an advanced algorithm
called Discrete Cosine Transformation (DCT), the movement and colours
in a motion picture are encoded in mathematical representations then processed
by XViD with an algorithm called quantization. When DCT is performed, 8 pixel
by 8 pixel blocks of the image are mathematically isolated. CDT then groups
four of these 8×8 pixel groupings into what’s called a macroblock.
The quantization process in XViD then converts the pixels in these macroblocks
to frequencies, and those macroblocks that are now represented as frequencies
correspond to detail. High frequencies equate to high detail, and low frequencies
equate to low detail. Once the quantization process has been performed by XViD,
it loads a Quantization Matrix which tells XViD what frequencies to
throw away. This is compression. The XViD codec itself allows the use of custom
quantization matrices to provide more or less detail. Amidst this quantization
process, XViD is constantly analyzing three types of frames:

  1. I-Frame: Short for intra-frame, these are unique and individual
    frames like a still picture. These come in user-selectable intervals and the
    full information of these frames are encoded.
  2. P-Frame: Short for predicted-frames, the information encoded
    in these frames only contains the difference in the frames prior to this type.
    If there’s an image static between two frames, say a light changing from blue
    to orange, only the light changing from blue to orange will be encoded.
  3. B-Frames: Short for bi-directional-frames, these frames
    reference the frame before and after it to conclude the best frame to reference,
    if not both of them, to get the best quality out of this frame.

And when all is said and done, quantization complete, I/P/B-Frames analyzed
and encoded, XViD encoding is complete.

XViD itself operates inside a container format. A container format is simply
a recognizable format with which audio/video and other miscellaneous features
are packaged. Matroska, OGM and AVI are three of the most common MPEG-4 container
formats. Based on the container format you use, your video can contain any of
the follow features: AC3 audio, MP3 audio, OGG audio, multiple subtitles, multiple
audio streams, DVD-like menus, chapters, and more. The features you require
will determine which container format you’ll need to use. A complete explanation
of container formats is next.

Container Formats:

As stated above, a container format is simply a recognizable format with which
audio/video and other miscellaneous features are packaged. There are many different
types (.divx, .mp4, .mpeg, .avi, .mkv, .ogm) however the three popular ones currently
available are:

Matroska – (.mkv)

The new kid on the block of the container
formats, and the one I predict will become the premiere replacement for the AVI
package somewhere down the road. It is licensed under GPL, and it uses an architectural
scheme called EBML, which is a binary relative to the XML format. Its features
include:

  • Internet streamability
  • Fast seeking in the file
  • High error recovery
  • Menus (Like DVDs)
  • Chapter entries
  • Selectable subtitle streams
  • Selectable audio streams
  • Modularly Extendable

OGG Media – (.ogm)

So new that very little
is actually documented on its features. Also an open source GPLed container
format, like Matroska, it uses Xiph.org’s OGG Vorbis architecture to produce
a container schema that may hold XViD/DiVX/OGG Tarkin (Their planned GPL video
codec) and OGG Vorbis audio. Its features include:

  • Chapter entries
  • OGG audio support
  • Selectable subtitle streams
  • Selectable audio streams
  • (Soon) Multi channel OGG audio
  • Instantaneous file seeking

Audio/Video Interleave 2.0 – (.avi)

So what’s there
to say on one of the oldest MPEG4-compatible container formats? Not a lot. AVI
was originally designed by Microsoft with a 1GB file limit and was rather sparse
for features. Later, a group called OpenDML came by and retrofitted the container
format to support slightly faster file seeking, 4GB file sizes, and a new internal
file structure. Despite the fact that most of the features below could be perceived
as negatives, AVI isn’t really that bad. It’s a solid container format simply
lacking some of the amenities made possible by MKV and OGM based on much newer
languages. The introduction of VobSub and the development of ODML 2.0 AVIs has
increase AVI’s staying power, and with Microsoft/ODML backing it, it’s a juggernaut.
All AVIs today are ODML 2.0 AVIs, and its features include:

  • External subtitles
  • Slow file seeking
  • Dual Audio Streams
  • No streamability
  • No time base
  • Awkward meta structure

All Audio/Visual Wrapping Architectures Considered

If you need a feature-packed wrapper format, Matroska is what you want to use. Because of Matroska’s advanced features, it’s only offered in the intermediate and advanced sections of this guide. Maximizing Matroska’s potential is limited to the advanced section only. It’s best, however, to begin to familiarize yourself with the format as I predict it to be quite common soon. If you need a plain method of delivery, and don’t care about the fancy features, AVI is your choice. I still use AVI 99% of the time. Lastly, there’s OGM, the curiously undocumented wrapper that plays by itself at lunch time. There’s not a lot to know on it, and my suggestion is to avoid it until they allow 5.1 OGG Vorbis audio on it, then it’s going to become a real contender to DD5.1 + XViD in an MKV container.

Getting the Right Tools

Getting the right tool, or the right version of that tool is an important step in the world of encoding. Having outdated versions of any software can render unpredictable results such as oversized files, unsynchronized audio, artifacts in video and more. So when you go to invest time in any project, check to make sure you have the newest version of the software on your computer. Remember that all of these tools are completely freeware, and as such, typically don’t have large development teams behind them to scan for bugs thoroughly prior to release. With that in mind, these programs often receive more updates per unit of time than your average piece of retail software.

This software is updated as of October 11, 2004. Check
Google for the newest versions.

Codec/Software
File Size
Description
XViD v1.0.2
620KB
The newest version of the XViD codec at version 1.0.1.
AC3
Filter v0.70B
295KB
Rivaling commercial AC3 decoders, this is a freeware AC3 Codec.
Supports audio from mono to 5.1 and everything in between.
OGG DirectShow
Filters
464KB
The OGG Vorbis audio codec.
AutoGK
v1.60 Full
6.61MB
The set and forget XViD/DiVX encoding tool. The basic full package.
VirtualDubMod
v1.5.10.1
1.62MB
A powerful DiVX/XViD/Other encoding program with OGG/AC3/VBR-MP3/OGM/MKV
support. Includes many other features.
VirtualDubMod
Build 2439 Update
925KB
Update to VirtualDubMod.
Gordian
Knot v0.32 Beta
7.50MB
A robust XViD/DiVX encoding tool. The complete package includes
many pieces of software as well as GK itself.
AVISynth
v2.5.5
1.32MB
A ridiculously feature-rich frame serving application. Powered by
its own scripting language and acts as an interface between the source file
and the encoder.
DVDDecrypter
v3.5.1.0
808KB
A free DVD ripping program, the most robust of all available, and
the XViD community standard. Required for AutoGK and GK.
BeSweet
v1.5
474KB
The world’s best free audio transcoder. Capable of directly converting
MP3/DD-WAV/AC3/MP2 to MP3/DD-WAV/AC3/MP2. Command line only.
BeSweet
GUI v0.7B4
258KB
The powerful GUI for BeSweet. Converts the CLI-only BeSweet into
an intelligible product.
DGMPGDec v1.0.12
294KB
Also known as DVD2AVI, this fixed version of that exports .D2V projects
which allows source range encoding, IVTC/Interlace and framerate analysis.
130KB
A DLL file required for the normal operation of Gordian Knot AVISynth
filters.
MSVCR71.DLL
165KB
A second DLL file required for the normal operation of Gordian Knot
AVISynth Filters.
Total File Size
22.30MB

Familiarizing Yourself With XViD

When you first install XViD, you’ll have a clean configuration slate, and it’s preconfigured for compatibility and speed, not quality. Once you’ve installed the codec, you have to launch your start menu and locate the XViD entry in the
programs
menu. Once you’ve done so, launch the “Configure Encoder” entry, and it is here that you will be given access to all the features of the XViD codec. Remember that if an option is not explained, it’s generally untested/beta/very advanced/unnecessary. Once you’ve done this, you’ll be presented with this screen:

Default_XViD_Screen

Step 1 – Setting the Right Profile:

Set the “Profile @ Level” to (Unrestricted) and hit “More…”

Step 2 – Configuring the Profile@Level Settings

Configure_XViD_Profile

Configure the XViD Profile settings as per the picture, and ignore the “Level” and “Aspect Ratio” tabs.

Step 2a – Profile@Level Settings Explained:

Profiles:

Each profile complies with a different level of the MPEG4 standard.The closer to the bottom of the drop down the profile is, the more advanced it is. For example Simple@L2 has a framerate maximum of 15FPS and a video bitrate ceiling of 128kbps. Generally speaking, most encoders use the AS@L5 or the (unrestricted) profile. AS@L5allows the DVD resolution of 720×576, and a maximum of 30FPS as well as all the quality increasing options. The unrestricted profile allows access to all the features that XViD has to offer. If you wanted to make a 5000×5000 grayscale, interlaced, inverted, 60FPS video, unrestricted is for you. I tend to leave it on unrestricted so I have access to everything right from the get go.

Quantization Type:

You have three options here. MPEG sharpens the image, and is good for basic high-bitrate (>1000kbps) encodes, and H.263 softens the image which is better for medium-bitrate (800-1000kbps) encodes. The last option allows the entry of your own custom quantization matrix, which is recommended to maximize quality. The XViD installation gives you a variety of custom matrices in its start menu entry, feel free to extract them and try them in source range encodes. See which one is best for you. Generally there is no single “Best” matrix for encodes, because each source project is different. High-contrast videos can stand to use matrices that drop a lot of the deep black and sharp white frequencies in the DCT process, as the human eye can’t perceive subtle shifts in very dark and very light shades. Low-contrast videos must use matrices that drop off much less detail so as to preserve the subtle differences between objects. And furthermore, the desired sharpness of the final product must also be considered. If I were to recommend one basic quantization matrix, MPEG would be it, as I like a cleaner, sharper picture. However, as decent as the H.263 and MPEG quantization matrices are, users in the Doom9 community have created their own excellent matrices. My favorites are:

Dide’s SixofNine Quantization Matrix (Recommended Usage: 2CDs or More)

Enter the information for this matrix in the exactly corresponding
location and then “Save Matrix” so you can load it again in the future.
It is generally advisable to avoid this quantization matrix at all costs
with video less than 800kbps.
Generally this matrix is good for content
between 800-1000kbps.

08 10 11 12 12 13 14 15
10 11 12 13 13 15 15 16
11 12 12 14 15 15 16 17
12 13 14 15 15 16 17 18
12 13 15 15 16 17 18 19
13 15 15 16 17 18 19 19
14 15 16 17 18 19 19 20
15 16 17 18 19 19 20 20

10 10 11 12 12 13 14 15
10 11 12 13 14 14 15 16
11 12 12 14 14 15 16 17
12 13 14 14 15 16 17 18
12 14 14 15 16 17 18 19
13 14 15 16 17 18 19 20
14 15 16 17 18 19 20 20
15 16 17 18 19 20 20 20

Enter the information for this matrix in the exactly corresponding
location and then “Save Matrix” so you can load it again in the future.
It is generally advisable to avoid this matrix at all costs with video
less than 1000kbps.
Generally this matrix is good for content 1000kbps
or more.

08 11 12 12 13 15 16 17
11 11 12 12 14 15 16 17
12 12 13 14 15 16 17 18
12 12 14 16 17 18 19 19
13 14 15 17 19 20 20 20
15 15 16 18 20 21 22 22
16 16 17 19 21 22 23 24
17 17 18 19 20 22 24 24
12 11 12 12 13 14 15 16
11 11 12 12 13 14 14 16
12 12 12 13 14 15 16 17
12 12 13 15 16 17 18 18
13 13 14 16 18 19 19 20
14 14 15 17 19 20 22 22
15 14 16 18 19 22 23 24
16 16 17 18 20 22 24 24

Jawor’s 1CD Matrix (Recommended Usage: 1CD Rips):

Enter the information for this matrix in the exactly corresponding location and then “Save Matrix” so you can load it again in the future. It is generally advisable to avoid this matrix at all costs on rips larger than 1 CD. Generally this matrix is good for content between 500-800kbps.

08 08 10 12 14 16 18 20
08 10 12 14 16 18 20 22
10 12 14 16 18 20 22 24
12 14 16 18 20 22 24 26
14 16 18 20 22 24 26 28
16 18 20 22 24 26 28 30
18 20 22 24 26 28 30 32
20 22 24 26 28 30 32 32
17 19 21 23 25 27 29 31
19 21 23 25 27 28 29 33
21 23 25 27 29 30 32 37
23 25 27 30 31 34 40 45
25 27 29 31 38 46 54 60
27 28 30 34 46 58 72 74
29 29 32 40 54 72 90 100
31 33 37 45 60 74 100 124

HVS-Good-Picture (Recommended Usage: 1-2 CD Rips)

Luckily for you, this matrix is precompiled in the matrix archive that comes with the XViD 1.0.1 on this tutorial. Simply extract hvs-good-picture.txt to your desired location, and load it in the “Custom Matrix” window. It is generally advisable to avoid this matrix on low bitrate/ultra-low bitrate content. Generally this matrix is good for content between 800-1000kbps. As an alternative, try HVS-Best-Picture in the same archive and compare your results.

Adaptive Quantization

The first “Psychovisual” enhancement to the XViD codec. Adaptive quantization preys on the fact that the human eye is much less perceptive to encoding errors in very dark or very light fields than it is in high-detail fields. What adaptive quantization does is allow the XViD codec to apply different low-detail quantization values for different macroblocks
which allows saved bits to be redistributed into the detail portions of the film. At this time it is still experimental, and possible side-effects of its use includes film blocking. I typically leave it disabled, however there’s no harm done in encoding a small segment of your film with the option disabled, then enabled, to compare both of them. When you do it, try to pick a segment of the film where the first half is very dark or light, and the second half is of normal detail. This will give you a good idea of how well it works. Test this option, and use it differently from project to project.

Interlaced Encoding

This encodes your clip as a pure interlaced product. For this to work your source must firstly be of a truly interlaced. Commonly interlaced sources are camcorders and live TV broadcasts. The rest of the sources that appear interlaced are really not interlaced at all. They’re mutilated progressive streams that have had a process run on them called telecining. Telecining is a process by which a 23.976 FPS (FILM) stream has frames doubled and blended to produce a smooth 29.976 FPS (NTSC) image. The problem with this is that XViD doesn’t need a 29.976 FPS stream to play properly, so we run a process called inverse telecine (IVTC) to correct these doubled and blended frames, thus isolating the pure progressive content of 23.976 FPS. Leave this option off.

Quarter Pixel

Quarter Pixel, also known as Q-Pel from here on out, is a tricky option to use correctly. Q-Pel is a modification to the way XViD analyzes the movement in B-Frames and P-Frames. Typically XViD motion analysis judges motion detail by half pixels and mathematically expresses them with a single post-decimal integer (0.x)
. Q-Pel, on the other hand, increases the mathematical motion vectors in I/B-Frames to two post-decimal integers (0.xx) for a more scrutinizing analysis of all the frames in your project. Q-pel does not increase quality in a direct sense, rather it allows finer mathematics to increase the compressability of your project. The catch with Q-Pel is that the amount of texture bits saved must be higher than the bits needed to analyze every frame with two post-decimal values. So, all told, it’s impossible to tell if Q-pel will help or hurt. What’s the trick to using it? Run a compressability test with AutoGK with QPel enabled, and then disabled. Check the compressibility values reported. If QPel enabled has a higher rating than disabled, leave Qpel enabled. If it’s vice versa, turn it off. Generally, however, QPel is a good thing.

Global Motion Compensation

Global Motion Compensation (Henceforth known as GMC) attempts to combine all the mathematical expressions for macroblock motion into a single motion vector (Which is why it’s called global motion compensation). If you have multiple macroblocks (Remember, a grouping of 4 8×8 blocks) moving in a similar direction, XViD would apply a motion vector to each of these blocks individually without GMC. But since they’re all moving similarly, it would make sence that all of them have a common vector, thus alleviating wasted bits by using the same vector several times. Turn it on! The bits saved go to increasing quality.

Reduced Resolution

This setting doesn’t actually affect the resolution of the image itself (### x ###), instead it restricts motion compensation vectors to crippled values and applies them to a non-standard macroblock sizing. The goal of this setting, which only works with ARTS and unrestricted XViD profiles, is to keep the entire picture visible if bandwidth were suddenly to drop to a minimum. The ideal application for RRV is mobile phone playback. Don’t ever enable this.

B-VOPs

Max Consecutive BVOPs: This setting controls the amount of B-Frames that appear in a video sequence. Generally the advisable setting is 2.

Quantizer Ratio: (Quote the Unofficial XViD FAQ) “Multiplying the (average) quantizer of the surrounding non-B-frames with this value will give you the Quantizer of the B-frame. So if the two adjacent frames have quantizers of 2 and 4, the average quantizer will be 3. Multiplying this with a quantizer ratio of 1.50 will give you a B-frame with a quantizer of 4.5.” Generally the advisable setting is default.

Quantizer Offset: (Quote the Unofficial XViD FAQ) “Take the result of the calculation above and then add this value. With a quantizer offset of 2.00 you will end up with a quantizer of 6.5.

As a rule of thumb, upping the latter two values will give you lower quality B-frames.” Generally it is advisable to leave this setting at its default.

Packed Bitstream:

Amongst AVI’s weaknesses is the inability to cope with frames that
are out of order. Not as frame #231 comes before frame #23, but in the sence
that the wrong type (P/B/I-Frame) comes early. This is a good option
in theory, having perfect frame sequences, but more than a few problems have
actually been reported with its usage. Turn this setting off!

Closed GOV:

Makes sure that a P-Frame comes before every I-Frame. If this option isn’t enabled, you can have something weird like a B-Frame being wasted on a forward reference to an I-Frame. Always leave this enabled.

Step 3 – Return to the Main Codec Configuration Screen

Default_XViD_Screen

Ignore the other two tabs, as configuration there is generally unnecessary and the options are advanced enough that I’m still working on understanding them. Now that you’ve completed the profile configuration, it’s back to this screen.

Step 4 – First Pass Settings

1st_Pass_Config

Change the encoding type briefly to “Twopass – 1st Pass” and hit “More…” Configure as shown.

Step 5 – Configuring XViD’s Advanced Options

Advanced_Options_MotionTab

Exit back to the main screen of XViD and hit the “Advanced Options” button at the bottom.

Step 5a – XViD’s Advanced Motion Options Explained

Motion Search Precision

When the encoder is undergoing the process of quantizing your source material, the first step in analyzing it is via motion search. This value searches only for changes in brightness (The luminance plane), as the human eye is much more sensitive to brightness than colour. The maximum and recommended setting of 6 has a marginal performance impact, and never go below 5.

VHQ Mode

VHQ considers other elements of the picture to conclude an increase in quality. It accounts for colour accuracy, motion, and several other variables. For quick encodes, a value of one is suggested. For high-quality encodes, a value of 6 is suggested. Your encoding performance will be severely impacted at level 6, but it’s worth it.

Use Chroma Motion

Chroma Motion is roughly equivalent to Motion Search Precision 7. It takes colour into account when doing motion searching. Recommended enabled.

Turbo Mode

Turbo mode bypasses some rudimentary search techniques with Q-Pel and B-Frames, thusly accelerating the encoding process with little to no impact on quality. The suggested setting is enabled.

Maximum I-Frame Interval

Remember that I-Frames are unique frames that are compressed as single
images. They don’t have any motion compensation to them, and they do not reference
any other frame. These frames are also called keyframes, and in the world of
Matroska and DVDs, keyframes are where you insert chapters. In addition to I-Frames
being chapter-insertion points they are also the frames by which players search.
You’ll notice that when you fast-forward a DVD or any AVI file, there are multi-second
jumps between the images. This is the seeking of keyframes. A general rule of
thumb is to make the I-Frame interval 10x the rounded FPS of your destination.

  • 23.976 -> 24 = 240 I-Frames
  • 25.000 -> 25 = 250 I-Frames
  • 23.976 -> 30 = 300 I-Frames

Step 5b – XViD’s Advanced Quantization Tab

Quantization_Tab

The only option really necessary for configuration in this menu is the Trellis quantization setting. Trellis quantization is basically an adaptive quantization method that is an extra step in the DCT process. It drops some DCT vector coefficients in favor of recovering some of those lost in the initial DCT process. Obviously dropping coefficients can be harmful to the quality, but if the bitrate saved from recovered coefficients outweighs the bits discarded from Trellis, the overall video quality will be increased. There’s no telling in advance if it’ll be good or bad for your encode, generally it’s good to turn it on, but try with and without it first.

Step 6 – Configure “Twopass – 2nd Pass” Advanced Options

Default_XViD_Screen

Return to the primary configuration screen of XViD and switch the encoding type to “Twopass – 2nd Pass.” Once again return to the “Advanced Options” screen and configure the options exactly as in steps 5 and 5A.

Step 7 – Zones Explained

Zone_Options_Config

The XViD codec allows the user to define specific parameters for different
section of the video. This includes encoding the credits of a film with much
less accuracy so as to provide many more bits to the rest of the film, where
it counts. However, I generally like to leave the entire movie as one large
zone, and alternatively use my encoder to specify alternate credit encoding.
This gives me full detail throughout the film and retains the added benefit
of bit redistribution. There are two critical options to set in this menu and
they are in red and set as they should be configured.

Step 7a – Zone Options Explained

Chroma Optimizer Enabled

The chroma (colour) optimizer in XViD does another level of critical analysis
in the chroma channels of a source file to reduce hard/stair-stepped edges.
This setting increases the mathematical deviation between source frame and result
frame, however, as a psychovisual enhancement, the subjective quality will be
superior.

BVOP Sensitivity

This allows you to tweak the amount B-Frames in each zone. A practical value is 5.

Step 8 – Determining File Size

Mini_Bitrate_Calc

The XViD 1.0.1 codec package that comes with Nic’s MiniCalc which can be accessed from the start menu

Step 8a – Minicalc Options Explained

Film Length

This field simply requires to put the length of your movie in in HOURS.MINUTES.SECONDS. Remember to separate it with periods.

FPS

Generally, even in the United Kingdom and other non-NTSC locales, you’re going to want to select 23.976 FPS.

Audio Bitrate

For 1CD encodes, your audio bitrate should be 128-192kbps (MP3). For
2 and 3CD encodes, the choice is yours: Either select 224kbps for 2 channel
AC3 (Very nice picture), or 448kbps for 5.1 channel AC3 (Slightly worse picture).

Subtitle File size

If you’ve ripped the subtitles of your DVD with VobSub (Later in this guide), you’re going to want to load the subs for it.

Final Size

700MB (1CD) – If your audio is 128kbps MP3 you can fit 1:34:00 of footage in at near-DVD quality. If your audio is 192kbps MP3, you can fit 1:28:00 of footage in at near-DVD quality.

1400MB (2CD) – Using 2 channel AC3 audio at 192kbps, you can fit 2:56:00 of footage at near-DVD quality. If your audio is 5.1 channel AC3 audio at 448kbps, you can fit 2:15:00 at near-DVD quality.

2100MB (3CD) – Requires manual entry and should be reserved for movies that are Lord of the Rings in runtime. Always use AC3 audio.

What’s the trick for final size? It’s hard to say. If the movie’s runtime is about 90 minutes, see what a sample looks like using the 700MB destination size. And then compare it to an encode which separates the movie into 2 45 minute chunks. Basically, if the movie is close to 2 hours (Give or take), calculate the full movie, but split it in two later. If the movie is close to 3 hours, calculate and split it into thirds.

For example, to select a movie on the market currently, the Manchurian Candidate Anniversary DVD has a run time of 126 minutes. If I wanted to stuff it on a single CD, I would use 192kbps MP3 audio and set the destination size to 700MB. If I wanted two CDs for better audio (AC3), I would set the destination for 1.26.00 length with a 1400MB file size. A good rule of thumb for ALL DVD rips is to make 2CDs out of it with the runtime of the film split in two.

Overhead

Mixing audio streams with a video stream requires a certain margin of overhead to give the container format details about how the audio is interleaved. Pick your audio type.

When you’re all done, it’ll produce a value called “XViD Video Size:” and this is the value you want to copy and paste into the window for step 9 below.

Step 9 – Configuring XViD for File Size

Configuring_File_Size

Unlike other codecs, XViD does not judge the final file size based on bitrate, rather it uses a file size to determine the variable bitrate the video will use. Since the best results in XViD are achieved with two passes, and the first pass is an analytical pass, you’ll want to switch to “Twopass – 2nd Pass” on the main option screen of the codec. Take the value from your minicalc in step 8A, and paste it into “Target Size (kbytes)”

Your codec is now completely configured. Remember that you must change the target size every time you make a new project, as the target size is based off your source length and desired audio.

Beginner/Quick Encoding – AutoGK

A derivative of GordianKnot, AutoGK is the world’s first quality-minded
set-and-forget DVD to XViD/DiVX program. Using a grand compositing of quality
freeware programs underlying a clean and effective interface, the goal of AutoGK
is to reduce the difficulty of encoding in XViD whilst retaining the quality
typical of other encoding methods. There are other programs out there that can
do what AutoGK can, such as DVD2AVI, however none of them can do it quite as
well, nor can they do it as easily as AutoGK allows. In exchange for very quick
encodes comes a lack of precise control. By all means, however, if you
want to just get a good XViD encode done, use AutoGK
. You rip your
DVD, select that source with AutoGK, set a few options and AGK does everything
else for you. Audio encoding, splitting, muxing, video encoding, splitting,
subtitles.

Typically, if I don’t feel like fussing with more advanced methods of encoding, I run through AutoGK and get done with it. Even if you’re an advanced user of the XViD codec and the appropriate software, the ease and speed of AutoGK is a breath of fresh air. Don’t think that understanding the advanced tutorials means you’ll never come back to this program again. Without further ado, here’s how to encode in AutoGK.

Step 1 – Ripping Your DVD:

The standard DVD ripping procedure is DVD Decrypter. Every program to encode
XViD in this tutorial requires DVD Decrypter material. So learn it and love
it.

Step 1a – Setting DVD Decrypter to IFO Mode

DVDDecrypter_IFO_Mode

DVD Decrypter, by default, rips all the streams on the DVD to disc, but we don’t really need all that information most of the time.

DVDDecrypter_Stream_Processing

By enabling IFO mode we can set it to pull only the streams we want, and that’s a good thing. Only extract the streams that are right for you. A good rule of thumb is to extract the primary video stream, and the 6CH AC3 audio stream as the audio can be manipulated to 2CH AC3 or 2CH MP3 later via BeSweet. For the purpose of this tutorial, I’m also ripping the English subtitles. Once you’ve selected your streams…

Step 1b – Dumping the DVD Files to HDD

DVDDecrypter_HDD2DVD

Click the DVD to HDD button and wait for this screen to go away. It will generally take approximately 20-45 minutes to dump the DVD to your HDD. Go get some tea or coffee.

DVDDecrypter_Dumping_Process

Step 2 – Familiarizing Yourself with AutoGK

Configuring AutoGK is a very easy process, as most of the “Hard” parts in the encoding process are already figured out for you. This is the main screen of AutoGK and every option is important:

AutoGK_Main_Screen

Step 2A – AutoGK Options Explained

Selecting Your Input Type:

In accordance with this guide, you’re going to want to set the program to to DVD Input. However if you ever wanted to encode .m2v, .mpeg, or .mpg, select file input.

Input Directory

Set this path to the VIDEO_TS folder in the destination you selected for your DVD rip.

Output File:

Set this to the name of your output. Do not include anything like CD1 because AutoGK will automatically name the files sequentially.

Audio Track

Since you ripped 6CH English audio and 2CH audio, it’s time for you to make a choice. If you want the full 5.1 channels, select 6CH AC3. If you just want stereo, select 6CH AC3 anyway and wait for the Advanced Settings configuration.

Output Size

Remember the long and fairly nebulous explanation on how to adequately select the output size? Here it is. If the movie is roughly 1:30:00-2:45:00, hit the 2CD rip. If the movie is 2:46:00-3:00:00+, hit the 3CD rip.

Subtitle Track

Generally it doesn’t matter which sub you pick, as long as it’s defined as “Normal” and in your own language. See advanced settings screen for more options.

Step 3 – AutoGK Advanced Settings

Click the “Advanced Settings Button” to hit this screen. These options aren’t particularly advanced, but they’re all very useful:

AutoGK_Advanced_Options

Resolution Settings

Let AutoGK decide the optimal size for your video. If you fix the width
manually, you could be cheating yourself of a larger image. Secondly, you can
actually make the smaller image look worse than the bigger frame that auto will
probably produce.

Codec

XViD.

Audio

Since you’ve already selected AC3 6CH, here’s the point where you decide
what to do with it. If it’s a 2 or 3 CD rip and you want 2 channels, go with
256kbps VBR MP3. If it’s a 2 or 3 CD rip and you want the full 5.1 experience,
check AC3. If it’s a 1CD rip, definitely go with 128-192 CBR MP3. Generally
it is advisable to use 2 channels for everything unless you really like 5.1
audio.

Subtitle Options

There are two sorts of subtitles. One is “Forced subtitling” and this is where the DVD only displays subs for portions of the film that are outside of the native language of the viewer. For example, at the end of Return of the King where Galadriel, Celeborn and Elrond are speaking to the Hobbits in the Grey Havens, Elvish is spoken. It makes sense to subtitle that, but not the rest of the film. If you’re going for subtitling where it makes sence, check forced subs. The second kind subtitles the entire movie. Generally forced subs are a good idea, unless you need full subtitling.

Step 4 – Starting the Encode

AutoGK_Main_Screen

Once you’re back to the main screen, you need only “Add Job” and “Start!”

If you feel so inclined, you can get a very rough idea of how your video will
look by hitting the preview button. But it doesn’t take bitrates, or your XViD
codec configuration into account. The preview option is more to check the auto-resize
and subtitling options, to see if they worked appropriately. Furthermore, if
you’ve ripped multiple DVDs, you can use different settings for different files
and add them to the batch encode list. AutoGK will automatically process the
files with the settings you’ve selected. And when you’re done, you’ll get something
like the following! Each shot required a significantly varying bitrate and attention
to detail, and I think it came out very sharply. This encode used all the XViD
codec settings in this guide, and was a 3 CD rip using Didee’s SixofNine quantization
matrix. The resulting bitrate was approximated to 843kbps, this is approximately
SEVEN TIMES less than an average DVD
. The images here are in PNG format
so as not to lose any detail via compression:

Sm�agol Ponders the Meaning of Life in a Fishing Grub:

AutoGK_RoTK_Shot1

Notice the sharp detail across Andy Serkis’s eyes and in the creases of his
forehead. Didee’s quantization matrix has done an excellent job of isolating
and maintaining detail in the encode. Furthermore, even the grain of the skin
is preserved to an admirable extent and nothing looks washed out or pixelated.
XViD and Didee’s matrix managed to preserve subtle variations in both the chroma
and luma channels providing a very clean picture.

Faramir and the Soldiers of Gondor Ride to Meet the Orcs in Osgiliath:

AutoGK_RoTK_Shot2

Again notice the general sharpness of the picture, including the full detail
of the etchings on Faramir’s armor as well as the visibility of each individual
chain link on his mail. Didee’s matrix as well as the XViD codec is handling
the high motion in this scene very well, preserving the detail of the other
riders and their steeds expertly. The sharp contrast between the foreground
and the foggy background is also handled very well, and it seems QPel also took
a liking to this film, as none of the artifacts indicating its failure are present.

Aragorn Receives Anduril and Ponders Destiny in its Sheen:

AutoGK_RoTK_Shot3

Still maintaining the detail that is typical of XViD and Didee’s SixofNine
quantization Matrix, this scene could present something of a challenge to many
encoders. It’s a difficult combination of bright and dark, except the contrast
isn’t stark. The luminosity of the image varies sharply between regions, however
the luminosity changes are achieved via gradients of colours and brightness.
The codec and matrix must accurately calculate this difficult scene or else
the result is of objectively poor quality.

As a fair warning, if your playback seems visibly sluggish, merely pause the
video once and resume it. I ran into this peculiar effect amidst playback, and
all was corrected upon doing so. This odd occurrence may or may not manifest
on your own system.

Intermediate Encoding – Gordian Knot:

Gordian Knot is a relatively seasoned program in the wide world of
XViD. Developed by an amalgamation of people in the XViD community and packaged
primarily for Doom9.org, Gordian Knot has been something of a down-hill locomotive
lately. It keeps picking up speed and plows through everything in its path on
its way to stardom. Suffice it to say, its stardom is also well deserved. It’s
simply an interface for the composition of the industry’s best freeware programs,
however Gordian Knot does it very well. With a robust set of options that are
accessible to the new comer with some studious self-learning, and refreshingly
detailed to the veteran, Gordian Knot is a program worth having on your hard
drive.

Gordian Knot uses a relatively simple tab-based interface jam packed with options
on each tab. At the heart of Gordian Knot, like AutoGK, is a copy of VirtualDubMod
and AVISynth. AVISynth handles all the advanced filtering like cropping, resizing,
and detail enhancement, and then VirtualDubMod uses the AVISynth script’s frameserving
language to encode your video.

Step 1 – Ripping the DVD

DVDDecrypter_IFO_Mode

Unlike last time, Gordian Knot generally likes having the full DVD at its disposal to process. In order to do so, you set DVD Decrypter’s mode on IFO.

DVDDecrypter_IFO_Input

And then leave it on the “Input” tab.

DVDDecrypter_Chapters

Before you proceed with ripping, there’s one more step you must take to ensure
you have the proper chapter information available to Gordian Knot when the time
comes. Click tools, then settings, and then the IFO Mode tab. Make sure that
“Chapter Information – OGG” has been selected. This will export a
listing of chapter names and timecodes that GK will be able to import for both
the Matroska and OGM containers.

DVDDecrypter_Dumping_Process

And then dump it to disk via the DVD -> HDD button. As a fair reminder (Or
first notice if you skipped to the intermediate section), the ripping time on
a DVD averages approximately 30 minutes:

Step 2 – Preparing the VOBs for Gordian Knot

GK_Prepare_VOBs

Open Gordian Knot now and skip to the program section entitled “2 – Prepare the VOBs:”

Step 2A – Working with DGIndex

DGIndex_Open

Click the RGB film reel button, and you’ll be presented with the main screen
of DGIndex. DGIndex is a frameserving application in and of itself. It’s capable
of detecting interlaced, film, and telecined streams as well as processing VOB
files via a miniscule interface file that other programs can understand. This
is the basic element to frameserving; one program decodes the information in
a certain set of files and presents it to another program in an understandable
format, whilst processing the files in ways that the program it’s frameserving
to can’t understand. In this case, Gordian Knot can’t understand VOB files nor
can it demux audio streams or any of the other things we’re going to tell DGIndex
to do. Tell DGIndex to open your VOB files.

DGIndex_Add_Files

And get this screen.

DGIndex_Demux_All_Audio

Once you’ve auto added your VOB files to the listing, that window will close and the main DGIndex window will expand and now it’s time to set the program to demux all the audio streams. This step is necessary, as the resulting independent audio stream will be used later in encoding/remuxing.

DGIndex_Stream_Preview

Once that’s done, go to file and hit preview. The goal here is to find out whether or not you have a proper non-interlaced stream or not, so the next step is to preview the stream and check for noninterlace assurity.

DGIndex_Noninterlace_Assurity

Which will produce the stream preview screen. The goal here is to check if the stream is ‘FILM’ with an assurity rating of 95% or higher. If you’re in a PAL area, it’ll report with 95% assurity that your source is PAL.

DGIndex_Forced_FILM

And here we see that it is in fact a progressive image that’s 99% FILM. Since this is well above the 95% mark, I can go ahead and check the following option which forces DGIndex to report a 23.976 IVTC (Inverse Telecine) process in the frameserving file. If, however, the file is not 95%+ FILM, set it to none and proceed as planned. If your source is PAL, do not check force film, leave it at none

And once that is checked, you merely have to hit F4 and select your destination for your project and wait a minute or two for your VOBs to process. Once they’ve been processed, you’ll be loading the newly-made .d2v project that DGIndex has produced with Gordian Knot. As a note, if you wish to encode a small portion of the video, you need to use the slider at the bottom of DGIndex to locate your starting position and then hit the [ button. This marks the intro. With the same slider, locate the end of the portion you want to encode and then hit the ] button. This marks the conclusion of what’s called source range encoding. It is best to source range encode to test options before you encode the entire project, only to discover that your settings are incorrect. To reset the source range for FULL vob processing, merely move the slider to the beginning of the film and mark the intro, and then move the slider to the end of the video and mark the conclusion.

Step 3 – Opening the Prepared VOBs in Gordian Knot

GK_Open_VOBs

Now it’s time to open your processed VOB files, and to do so you need to focus your attention on the bottom of the main Gordian Knot window

Step 3a – Saving the Project

Before you open your VOB files, select a save slot in the “Save” portion of the window and rename it. Type whatever you want, as the name is not of particular importance but is nonetheless a required step.

Step 3b – Open the Processed VOBs

Once your project is named, open your .D2V file via the open button at the lower left of Gordian Knot. Do not close the window that opens.

Step 4 – The Bitrate Tab

GK_Bitrate_Tab

Once you’ve selected your project slot and opened the D2V project, it’s time to calculate the bitrate of your A/V stream. To do so, proceed to the “Bitrate” tab in Gordian Knot.

Step 4B – The Bitrate Tab Explained

Everything on this page is of decent importance as it all influences the final quality of your encode. This page is to calculate bitrate, to state the obvious, and it does so by mathematically computing several values. Everything from the length of your source, the codec for encoding, to the container format you use will impact this final bitrate.

Container

As we discussed, here is where you will select your container format based on the options you desire. Using the same Return of the King DVD sample as is consistent, you can see that it’s offering 1438 kBit/s to a 00:01:55 segment of video with the AVI container. All settings consistent, OGM only offers 1431 kBit/s and MKV offers the highest at 1442 kBit/s. You can pick XViD for a very safe and highly compatible format, however if you desire chapters and the bitrate increase (Which can add up over time), pick MKV. I’m going to pick MKV to demo chapters later.

Mode

As you want to be able to select the number of CDs, and the size that those CDs represent, it’s advisable to set the mode to “Calculate Average Bitrate.” The other option is suitable for DiVX 5/DiVX 3.11 where a calculator will determine what bitrate to use to properly calculate the number of CDs.

Duration

These details are automatically concluded when you load your DGIndex frameserving project, but nevertheless the title of this section is self-explanatory.

Audio A

Because of the way DGIndex unloads the audio from your DVD files into an independent
audio stream and dumps it to disk, you’ll have to load it here by hitting select
and picking the “448kbps” audio stream for 5.1 audio, or the 224kbps
audio stream for 2.1 audio. 2.1 audio is advisable for high video quality,
5.1 for better audio but diminished video quality. The quality
of the audio will not be any lower with the 2.1 stream, your speaker system
(If 4.1/5.1) will merely clone the stereo channels to the rear speakers and
send the front left/right to the center channels.

Audio B

If you want to include an alternate audio stream (Such as a director’s commentary from the extra features disc), here’s where you would load it. Using the very same method to rip the DVD in the introduction of this section, you would load the unmuxed .AC3 file for the commentary in Audio B’s section. It is generally advisable to reencode Audio B to MP3 so as to give as much bitrate as possible to your video stream.

Files

Here’s the section where you load the subtitles for your video that you’ll process in the subtitles/chapters tab. We’ll address that later, but be reminded you have to come back to this section.

Codec

Obviously XViD.

Total Size

Merely select the number of CDs you desire (Remember the explanation of suggested file sizes in Step 8, Familiarizing Yourself with XViD. Also be sure to set the CD size to 700mb, as 650MB CD-Rs are very rare.

Video and Interleaving

Check “Calculate frame overhead” and set the dropdown for
Audio 1 for the type of audio you’ll be using in your final video. If you’ve
included a second audio stream in the Audio B section, you’ll
want to change the “No Audio” to the type of stream you desire.

Step 5 – The Resolution Tab

GK_Resolution_Tab

This tab concerns everything regarding your resolution. This includes cropping, aspect ratio, destination dimensions and conformance to NTSC/PAL resolutions. This tab also has a considerable influence on the final product of your video, as a value called “Bits per pixel” calculates the amount of detail per frame of video via the dimensions of your destination frame size. A larger image can reduce the amount of encoded detail, though an explanation of how to achieve the optimal setting for this value is in this section.

Step 5A – Resolution Settings Explained

Input Resolution

This value is automatically calculated as a result of the DGIndex frameserving file.

Input Pixel Aspect Ratio

This value is automatically calculated as a result of the DGIndex frameserving
file.

Crop (Before Resize)

Just set the model to smart crop all and hit “Auto crop.” All the black bars will be removed as desired, as well as (Sadly) a few pixels
around the rim of the actual video.

Output Resolution

Here’s a setting that must be configured with a compressibility test.

Step 5B – Compressibility Tests

GK_Preview_Window

A compressibility test is a quick pass of your source files with the XViD codec.
It uses all the settings you’ve defined and attempts to ascertain a good bits/pixel
ratio. In other words, it roughly determines the amount of compression you can
give it before objective quality will dip below an acceptable level. If you
remember that window I told you not to close when you opened the D2V project,
now is the time to reference it. Do so by shifting view to it, and then hitting “Save and Encode.”

GK_Compress_Check

Which brings this screen

Set the mode to 5% and tell it to run. My 2.3GHz Athlon XP processed 5% of an
03:47:40 movie in approximately 33 minutes with all the settings from this guide.
I assure you that the settings here are of high quality, but not very fast.
As with the DVD ripping, now would be an excellent time to have a cup of tea.
Once it is done, you can go back to the resolution screen and continue step
5A. Compressibility tests don’t work well with small sections of video
– And again, don’t close the video window!

Output Resolution

GK_Resolution_Tab

Once you have completed your compressibility test, it’s now time to
select your resolution. To do so refer back to the resolution tab.

GK_BPP_Value

And focus on the bottom section of the window.

When adjusting the slider, make sure the section squared in red does not dip
below .2. Any lower and quality will suffer. For this particular video (Return
of the King), a resolution of 640×256, with 5.1 audio works well and gives a
final bitrate of 1047kbps. For an even sharper picture, I would pick the 224kbps
2ch audio stream that DVD Decrypter dumped and my bitrate would be circa 1200
kbps. Whatever floats your boat, audio or video, though at this point I choose
6 channel audio since 200kbps in the video department won’t make much of a difference.

Step 6 – Subtitles/Chapters Tab

GK_Subtitles_Chapters

This screen provides a very convenient interface for the use of VobSub. It allows you to index subtitles for use in your video, as well as resynchronize them
if they happen to be off. Not only that, this is also the section where you
can add chapters to matroska files. We’ll be doing that.

Step 6A – Creating Subtitles

VobSub_Main_Window

To create subtitles, your first step is to click the configure
button, which will open the VobSub menu.

Click the open button, and switch the “File of type” mode to “IFO
and VOB, for creating idx/sub (*.ifo).” Open VTS_01_0.IFO and select the
destination for the subtitle files. This directory should be the same directory
in which your final AVI/MKV/OGM files will go. You’ll be presented with an additional
screen that lists much information about cells, PGCs, chapters and whatnot.
Simply select “00 English” (Or whatever your native language happens
to be), and then hit ok. VobSub will index the subtitles and save them to the
location you specified.

Step 6B – Creating Chapters

This step is rather simple. Make sure you have the Matroska or OGM container
selected on the bitrate tab, then check the box that says “Add chapter
info to video” on the Subs/Chapters tab. Then click load, and navigate
to the location you ripped the DVD to. Load “VTS_01 – Chapter information
– OGG.txt” and it will automatically fill the time codes and the chapter
names as provided by the DVD. If you’d like to change the names or the times
of the chapter, and have a comprehensive knowledge of the DVD, edit the entries
in the table.

Step 7 – Preparing to Encode

GK_Preview_Window

Returning back to this screen, press Save & Encode to once again brings this window.

GK_Encode_Options

Make sure all the options are set as you see them. Make absolutely sure that
you don’t select the subtitles in this window, as you want them to be independent
text files which can be loaded and unloaded for subtitles. If you select it
here, the underlying encoding program will integrate them into the movie itself
and you can’t turn them on and off at will. Making sure everything is all right,
hit “Save & Encode.” Save the .AVS file in any directory you choose.
That will be the script which powers the encoding process. AVS, or AVISynth
Script File, will make an appearance in the advanced section of this article.

GK_Final_Encode_Window

Hit save and encode, to be presented with this window. Check the box that says “Just mux” if you’re using AC3 audio, or select
one of the MP3 radio boxes and input your desired bitrate. Switch to the XViD
tab, and hit “Add Job to Encoding Queue.” It will ask you if you want
to proceed with encoding: If you do, proceed. Otherwise the job will sit in
queue until you give the command to encode. Once you give the command, Gordian
Knot will automate its processes and produce a final video. Come back in about
4-12 hours, depending on the movie, on a 2GHz Athlon XP. As a fair warning,
Gordian Knot 0.32.0 is a beta version; and it is very buggy particularly
around adding the job to the queue and beginning the encode. If the program
crashes, merely restart it, reload the D2V project, and attempt to Save & Encode again.

The results of the Gordian Knot encoding process will be quite similar to the
results achieved with AutoGK, as they use the same encoding engine, so I have
not included pictures of the results. Suffice it to say, the encoding with Gordian
Knot produced slightly softer images all around. I could correct this
by using a stronger and sharper quantization matrix, and zone encoding to redistribute
bits from the credits to the main part of the film, but it’s not really necessary.
The main power of the Gordian Knot encoding pack is in the volume of peripheral
features it supports: Chapters, precise compression values, compression tests,
precise resolution control, multiple audio tracks and a persistent encoding
queue.

Advanced Encoding – AVI Synth Scripting Language and Gordian
Knot

AVISynth.org says it best: “AviSynth is a very, very powerful
tool for video post-production. It provides almost unlimited ways of editing
and processing videos. AviSynth works as a frameserver, providing instant and
very fast editing without the need for temporary files. AviSynth itself does
not provide a graphical user interface (GUI) but instead relies on a script
system that allows advanced non-linear editing. While this may at first seem
tedious and unintuitive, it is remarkably powerful and is a very good way to
manage projects in a precise, consistent, and reproducible manner. Because text-based
scripts are human readable, projects are inherently self-documenting. The scripting
language is simple yet powerful, and complex filters can be created from basic
operations to develop a sophisticated palette of useful and unique effects.”

The basic function of a frameserver is to act as a mediator; it provides an
interchange language that imports the source and then provides additional features
(like effects, compositing, resizing, cropping, etc.) that the encoder/codec
itself doesn’t have, then passes it on to the encoder for final rendering. As
an example, AVISynth can be used to inflate the size of a DVD from 720p (Analogue
TV) to 1080p (HDTV) with no loss in quality, and perhaps even a subjective increase in quality: It does this by inspecting the source, applying the desired mechanics
to each frame, then passing each frame to the encoder which renders it via the
codec. AVISynth’s function is to powerfully augment the functionality of codecs
and encoders, and it does so by giving the user complete control of brand
new, and unique scripting language.

AVISynth is also tremendously versatile, allowing any program that supports
.AVS scripts to import a variety of source formats, including: VOB, DiVX, XViD,
MPEG1, MPEG2, ASF, Quicktime, and more. Formats that aren’t directly supported
via AVISynth’s default programming can be added via a robust plugin system.
AVISynth has the unique ability to have its feature set broadly expanded with
plugins that are declared at the opening of an AVISynth script. In addition
to format importing, the plugin system can add features to deinterlace, clean
edge noise, sharpen pictures, remove broadcast logos, remove video artifacts,
and more. The last element of its versatility is in the fact that it works with
some of the most power MPEG4 and MPEG encoders on the market: CinemaCraftEncoder
for MPEG and VirtualDubMod for MPEG4. The power of AVISynth is tremendous, and
it represents the height of custom encoding and video processing.

VirtualDubMod, as mentioned, is a powerful MPEG4 encoding engine. It has gained
popularity over the years because it directly supports a variety of audio and
container formats, as well as AVISynth scripts. Furthermore, it’s just fast.
Its speed and versatility, like AVISynth, has garnered considerable fame and
community accolade. VDM serves as the true backend to Gordian Knot and AutoGK.

Step 1 – Learning the Basics of AVI Synth

As a language-based frameserver, rather than a program, all the things
you will learn to do in AVI Synth will go into a text document that has the
.AVS file suffix. To begin an AVI Synth script, create a .TXT file with a name
you find logical. Rename the file to .avs and then open it with
notepad. The first step is to learn the syntax of AVI Synth. The basic syntax
calls the function, then supplies the switches within parentheses.

As an example: LoadPlugin(“DGDECODE.DLL”)

That line firstly declares the function, that is the loading of a plugin, then
the parenthetical element declares exactly what I want to load or do with function.
Don’t worry too extensively about the syntax, as all the commands native to
AVISynth are documented at AVISynth, and
all the plugins provide extensive syntactical documentation.

If you should wish to block a command out, precede the command with the pound
(#) symbol. For example, by placing the pound symbol prior to the plugin loading,
that specific command would be ignored:

#LoadPlugin(“DGDECODE.dll”)
mpeg2source(“hp-cd1.d2v”)
Lanczos4Resize(720,480)
AssumeFPS(23.976)

Additionally, should you wish to comment your script for clarity and/or distribution,
you can place the pound symbol after a command and write anything you want:

LoadPlugin(“DGDECODE.dll”) #Load DVD2AVI project importing
mpeg2source(“hp-cd1.d2v”) #Import my DVD2AVI project, declaring that
it’s an MPEG2 stream
Lanczos4Resize(720,480) #Use a sharp resize algorithm to bring the frame size
to 720 x 480
AssumeFPS(23.976) #Like Force FILM in DVD2AVI, this forces 23.976 FPS on the
source stream

Step 1a – Command Order

Any time you write an AVISynth script, you must be conscious of the order you
place your commands in. It’s typically best to load all your plugins at the
beginning of your script, and make sure you’re loading the right plugins! Some
specific file import types (DVD2AVI, for example) require plugins. Think of
what you want to do, then investigate the steps required to do it, then declare
the plugins at the beginning of the file. The plugins must either be in the
same directory as the script, or you must use the full path (C:AVISynthpluginsetc…)
between the quotes to call the plugins:

LoadPlugin(“DLL HERE”)
LoadPlugin(“DLL HERE”)


LoadPlugin(“DLL HERE”)

Then you have to import your source material:

LoadPlugin(“DLL HERE”)
LoadPlugin(“DLL HERE”)
mpeg2source(“source file”)

Note that I have specified that the source is an mpeg2 stream, and this instance,
I’m importing a DVD2AVI project that has VOB files as its source. Because I
have a DVD2AVI project as a source, I realize I would need to declare DGDECODE.DLL
to import it, and were I writing the script for real, I would include that plugin.
If you want to trim segments of the file, this should come after the source
call:

LoadPlugin(“DLL HERE”)
LoadPlugin(“DLL HERE”)
mpeg2source(“source file”)
trim(startframe,endframe)

After you’ve declared the plugins, source and trim, you must now declare inverse
telecine (Reverting a real 29.97 FPS stream to 23.976: Most
DVDs are not really telecined, but 23.976 streams reporting as 29.97 FPS to
devices, which is why assumefps(23.976) works well), deinterlace (720i streams;
common with digital camcorders), or cropping (Ditching black borders on DVDs).
There are NUMEROUS plugins available to deinterlace material, such as KernelDeInt
or FieldDeinterlacer. It’s best to simply experiment with those plugins and
see which one works best for you. As with Gordian Knot, you can determine interlaced
or FILM by previewing your ripped VOB streams in DVD2AVI and checking for FILM
or interlace assurity. Lastly, the syntax for cropping can be found on the AVISynth
FAQ. As usual, your source material will determine what you require. Typically,
any DVD content you use will not need deinterlacing, or IVTC. You can traditionally
use assumeFPS(23.976) for NTSC DVDs or AssumeFPS(25.000) for PAL DVDs and continue
as planned. So as not to complicate the script-building process, I haven’t included
the commands for that.

If you have to resize a source file, that should be the first thing you declare
after the plugins and importing. Effects require the final size of
the project to work.If you run a filter, then resize the video, your results
will be dramatically poor. Be aware that there are a multitude of resize types.
Lanczos is the sharpest resize method, and since everything I encode is higher
to high bitrate, I use it universally. See AVISynth’s documentation for an explanation
of resizing methods:

LoadPlugin(“DLL HERE”)
LoadPlugin(“DLL HERE”)
mpeg2source(“source file”)
Lanczos4Resize(width,height)

Once you’ve established your plugins, your source, and any resizing,
you can proceed to more advanced steps:

Step 1B – Calling Other Scripts

AVISynth adds another level of versatility to its functionality by
permitting the calling of other people’s scripts into your own. To do this,
you merely have to supply the import command:

Import(“Location to the other script”)

Once you’ve imported the script (Be sure to do this BEFORE you run
the features of the script), you simply use the creator-defined call to summon
the script’s features (More on this in a moment). As an example, I am using
Didee’s IIP (Integrated Image Processor) which is an advanced script that allows
you to take progressive sources and inflate them to 1080i/p with considerable
quality. At the same time it runs image denoising, sharpening, and a plethora
of other image-enhancing features. Its primary purpose is to take DVB streams
and clean them up for HDTV displays. It has a required number of plugins also.
I have commented the script so as to more appropriately explain its functions.

Import(“x:directorydirectoryIIP.avs”) #This calls the IIP script
into the script I wrote here

LoadPlugin(“undot.dll”) #This summons a denoising filter that removes
grain, required by IIP.
LoadPlugin(“MaskTools.dll”) #This calls a plugin that allows IIP to
mask off certain portions of the picture.
LoadPlugin(“WarpSharp.dll”) #This is a sharpening plugin, required
by IIP.
LoadPlugin(“DGDecode.dll”) #This allows me to import MPEG2 DVD2AVI
projects.
LoadPlugin(“LoadPluginEx.dll”) #This allows the importing of plugins
designed for AVISynth versions earlier than 2.5
LoadPlugin(“dustv5.dll”) #Another denoising filter required for IIP’s
usage.

mpeg2source(“test4.d2v”) #Imports a test DVD2AVI project.
## Import the IIP script. The author has defined “IIP” as the specific
command call. Notice it operates just like any other command function(“switches”)/function(switches)
=> iip(switches). Additionally, all the stuff in
IIP( ) was defined by the author. ##

iip( dest_x= 1024, dest_y= 576,
ss1_x = 1.414, ss1_y = 1.414,
duststr = 2, dustweight = 1.0, antiflicker1= true, antiflicker2= true,
detailcontr1=127, detailcontr2 = 255, contr_radius = 3, PixSharp=0.4,
ss2_x = 3.5, ss2_y = 3.5,
Xstren = 255, Xlimit = 255,
subpelstren= 1.0, flatweight = 64,
protect_floor= 4, protect_bias = 16,
dering = -60, dering_weight= 1.0, dering_floor = 16, dering_bias=8,
detail_floor= 1, EQ = 2,
warp_Y = true, warp_UV = false,
debug= “showall | compareH/V | protect | dering”,
cropx=32, cropy=16
)
# SCRIPT END

People have authored a great many scripts based on a significantly more advanced
knowledge of AVI Synth than most people have mustered, and they’re all free
for download. Including a powerful script inside your own can help you achieve
results you couldn’t otherwise program by yourself. I encourage you to search
around on Google and doom9.org to find scripts that may help you in completing
your projects.

Step 2 – Finalizing and Using Your Script

Create a new DVD2AVI project from your ripped VOBs just like I showed you how
to in the intermediary encoding section. You’ll need one to process your DVD
into XViD. To show the power of AVI Synth, I have gone ahead and used the script
above as my sample for the remainder of the advanced encoding section. Be
aware that I have saved the IIP
script
and saved it as an independent script. The commands I included in
my script are only a small portion of the total IIP process.
It looks
like this when completed:

Import(“x:directorydirectoryIIP.avs”) #This calls the IIP script
into the script I wrote here

LoadPlugin(“undot.dll”) #This summons a denoising filter that removes
grain, required by IIP.
LoadPlugin(“MaskTools.dll”) #This calls a plugin that allows IIP to
mask off certain portions of the picture.
LoadPlugin(“WarpSharp.dll”) #This is a sharpening plugin, required
by IIP.
LoadPlugin(“DGDecode.dll”) #This allows me to import MPEG2 DVD2AVI
projects.
LoadPlugin(“LoadPluginEx.dll”) #This allows the importing of plugins
designed for AVISynth versions earlier than 2.5
LoadPlugin(“dustv5.dll”) #Another denoising filter required for IIP’s
usage.

mpeg2source(“RoTK_Sample.d2v”) #Imports a test DVD2AVI project.
#Call IIP

iip( dest_x= 1024, dest_y= 576,
ss1_x = 1.414, ss1_y = 1.414,
duststr = 2, dustweight = 1.0, antiflicker1= true, antiflicker2= true,
detailcontr1=127, detailcontr2 = 255, contr_radius = 3, PixSharp=0.4,
ss2_x = 3.5, ss2_y = 3.5,
Xstren = 255, Xlimit = 255,
subpelstren= 1.0, flatweight = 64,
protect_floor= 4, protect_bias = 16,
dering = -60, dering_weight= 1.0, dering_floor = 16, dering_bias=8,
detail_floor= 1, EQ = 2,
warp_Y = true, warp_UV = false,
debug= “showall | compareH/V | protect | dering”,
cropx=32, cropy=16
)

GK_Encode_Options

Once you’ve got the script saved, and all the files in the right location,
it’s time to start Gordian Knot again, and return to this screen.

GK_AVISynth_Script_Editor

Hit the edit button to show the AVISynth script editor.

What you must do is copy and paste the parts of your script that aren’t present
in the Gordian Knot script. For example, I would move all my plugin entries,
the script import call, and the IIP commands. I did so, after I took the screenshot,
so the changes aren’t reflected. IIP is so slow that it encodes at .5-1 FPS,
so obviously I didn’t even bother to finish a sample. The real power of AVISynth
isn’t necessarily in the fact that it can upsize video (Via IIP, SharpResize,
or something else), but in what it can do to enhance the general quality of
the film. Denoising, film editing, fixing colours, correcting edge bleed, removing
VHS noise, removing manifest line noise, removing logos, sharpening the picture,
a powerful resizing engine, powerful deinterlacing, robust IVTC engine, and
the list goes on. The power of AVISynth is virtually limitless in regards to
video restoration/cleaning. For MPEG4, its main purpose is to provide instruction
to the encoder: To import the film, clean it up a bit, resize it, and send it
on its way. If you need deinterlacing, noise reduction and those sorts of things,
simply edit the AVISynth script within Gordian Knot to load your plugin, then
provide the syntax for your desired plugin. Generally you won’t need to call
complex scripts into your own, nor will you really need to write one yourself
(An .AVS file). Gordian Knot provides a good default script that you can add
to, that will also automatically save before you begin the process of encoding.
The basic goal of the script I had you write was to show you just how robust
and power AVISynth can get; if you take a look at the full IIP script, it can
begin to boggle your mind.

The advanced encoding section is rather vague because the sheer enormity of
this program makes it nearly impossible to educate beyond the syntax, some basic
features, and how to implement it in your process. AVISynth, however, becomes
a virtual must-have for proper MPEG2 encoding which is the next guide I’ll be
writing. It is the only way to control noise, resolution and sharpness with
the most powerful MPEG2 Encoder: CinemaCraft.

Conclusion – DVD2XViD v2.0 in Review

Within the guide I have outlined three ways to encode in the XViD format. From
quick, easy, and limited, to complicated, quick, and amazingly powerful . The
choice is yours to make based on the feature sets you require and the time you
have available to you to experiment. Over the course of the last three years,
a lot has happened and I’ve also learned a great deal. The drive to learn the
bigger and better programs is directly proportional to the user’s dissatisfaction.
There came a time when DVDx’s encoding just wasn’t as sharp, quick, or robust
as I would’ve liked. It didn’t properly handle AC3 streams. So I switched to learning
DVD2AVI + AVIMUX encoding which had a better lanczos resizer, and support for
AC3 mixing. Eventually that too didn’t support all the features I wanted to incorporate,
so I set out to learn the next step up which was Gordian Knot. So on and so forth.
Never remain satisfied with your tools, always find a way to make them work better
for you, or find a tool that is superior to what you’re currently using. This
method is advantageous in two regards: The first is that you’re always on the
edge of learning; that is you’re never really behind when new advancements hit
the community, you’ve learned the old material and you’re ready for the new methods.
The second advantage is that the quality of what you encode will be better, and
that’s the basic goal of anyone who’s currently encoding to MPEG4 and specifically
XViD with version 1.1 looming in the distance.

XViD itself, as you have seen, is a very versatile codec. Interfacing with a variety
of programs, and arriving with an excellent compliment of features, XViD stands
as a nimble and powerful codec constantly in a state of programming evolution.
Approximately every three months, the codec has a major revision which brings
new features to the table in terms of speed, quality, and compression. It’s well
ahead of DiVX in the size/quality ratio, and even farther ahead when you begin
to see how many features XViD has that DiVX just doesn’t. It’s not that
DiVX is poor, and I want to reinforce that. It’s just that DiVX is not as good as XViD.

My many hearty thanks go out to the crew at Doom9.org and their forums for being
on the bleeding edge of encoding, and for providing stable links to must-have
programs. My thanks also to dvdrhelp.com which was instrumental in helping me
find the spark to encode back in 2001; the reliable links for tools and helpful
forums have helped me conquer a great many problems in my early days of encoding.
Thank you to the readers of this article who should provide me with feedback in
the Icrontic Forums, so I can
make this as user-friendly as possible. Constructive and informative feedback
will help me tune the guide over the course of the next few months to bridge any
ambiguities and inaccuracies that may exist. While I have tried to approach this
from a standpoint that will guide people through it for the first time, and teach
them how to do it every time thereafter, there are probably some gaps that need
to be filled. Consider this a living document, open for revision. And my largest
thank you goes to Icrontic and the entire community that supports it. We’ve
a hardy crew, and a great crew, and I’d want to be no place else on the internet.
It is with great pride that the world sees this for the first time under Icrontic’s
banner.

Stay tuned for version 2.0 of the XViD/DiVX to DVD tutorial.

Comments

  1. Thrax
    Thrax There's a broken bold tag on page 8, a broken size tag on page 9.

    Enjoy folks. :)
  2. MediaMan
    MediaMan This is a truly detailed step by step body of work. This brings together every piece of relevant information you need to know and understand about XViD and it is a definite article for the printer.
  3. Shorty
    Shorty :eek: Wow. That's an ARTICLE & then some ...

    Good work Thrax, damn good work :thumbsup:
  4. Thrax
    Thrax I told ya it was gonna be a killer, my friend. :)
  5. a2jfreak File is v1.0.2, description is v1.0.1

    Codec/SoftwareFile SizeDescriptionXViD v1.0.2620KBThe newest version of the XViD codec at version 1.0.1.
  6. Unregistered yes, this is an excellent guide, well done!
    I was wondering, is this available as a download as well (eg pdf)???
    keep up the good work.
    dave
  7. Thrax
    Thrax I hadn't considered making it into a PDF, but given suitable time, it could be accomplished. I'll begin working on that this weekend.
  8. Unregistered that is realy nice mate, looking forward to it.
    dave
  9. Unregistered I just used the intermediate guide with gordian knot and the results are perfect! I've tried several guides and this one is TOP notch! If you have time you should definately put this guide into a .pdf file. I encoded a movie to be around 1100mb to fit 4 movies on one DVD using the LAME 3.90.3 dll with --alt-preset standard for sound and using the latest XviD so I can keep the originals put away and the results overall look just like the DVD, absolutely no artifacts/jerking/blocks like you can sometimes get with DivX type encodes. I must say that I'm more impressed with XviD quality than DivX Pro.
  10. Unregistered also... if you have any suggestions on encoding badly interlaced tv shows that are on dvd (example: saved by the bell) that would be greatly appreciated because im having no luck with them... the video is clean but its kinda jerky when deinterlacing in gordian knot
  11. Thrax
    Thrax Are you sure it's interlaced? The content may just be telecined, which is 23.976 FPS material tricked into displaying at 29.97 FPS.
  12. Unregistered yes it's interlaced... when i use dgindex and let it run to get what film type it is, it stays on NTSC/Interlaced and when the encode comes out the video isn't smooth, it's a little jumpy... it's looks like it's hiccuping... it also did the same thing on jay & silent bob strike back around halfway through the movie, it played smooth for the first half because it's progressive but it changes to interlaced from halfway to the end and the video is jerky like the tv show encodes... not sure how to solve that problem
  13. Thrax
    Thrax Is there any way you could get on AIM or ICQ and send me a piece of the video? I can attempt to sort it out. I'd only need a single chapter ripped to begin working on it. I have about 7 ways to try deinterlacing. Heh.
  14. Lobo688
    Lobo688 Just to say thanks for the helpful guide. Mostly how I have been doing it but adds some helpfull tips.

    Just to add some feedback. The images in the guide are slightly blury, around the text you get small spots. It's because they are jpg files. If you save original screenshots as gif or png then they will be smaller in filesize and beter quality!
  15. Thrax
    Thrax The feedback is appreciated, but it's not a result of the files being jpegs. It's the result of a decision of our primary content master, Mediaman. He's decided that he opposes images that you can click to inflate because he believes that they impede the continuity and smooth flow of an article.

    At times I disagree with the concept, as in my own article some very large windows had to be shrunk to very small sizes (Ruining important fidelity), but in the long run.. His concept helps more than it hurts.

    Shrinking the GIF or PNG images to the same size would've produced the same unfortunate result.
  16. Lobo688
    Lobo688 I must disagree with you here, please let me explain.

    I understand what you are saying about the click to inflate design. But for this article there are many 1:1 or 100% sized images (i.e. not shrunk).

    For example, here is the 1st jpg image from the article.
    http://www.short-media.com/images/mm/Articles/dvd2xvid2/Default_XViD_Screen.jpg

    Notice the jpg compression dots around the text. Most noticeable above the ax in maximum quality. This file is 25kb in size. (344x439 96dpi)

    Here I have save a gif file of the same screen from the xvid program.
    www.picsplace.to/044671/Default_XViD_Screen-new.gif

    Perfect quality (100% identical to the image you see when using the application).
    This file is 7kb in size. (Same dimensions 344x439 96dpi)

    The png does even better. Same perfect quality, but the file is 4kb in size!
    www.picsplace.to/044671/Default_XViD_Screen-new2.png

    I agree with you about the DVD Decrypter and other resized screen shots. These are shrunk and would still lose quality if save as gif. I did a quick test and saving these as jpg could be better then gif (same image quality for a slightly smaller file size).
  17. EMT
    EMT Two things for ya Thrax.

    1) If you're going for PDF, there's a nice freeware program called CutePDF (you may already know this) that adds a printer that simply writes to a PDF file. So if you put the guide in Dreamweaver or Word or whatever, you could get a PDF out very easily.

    2) I'm curious, do you know anything about RMVB? I'd like to convert some of my stuff to that format for storage space concerns but have made no progress.
  18. Unregistered do you have or know of a guide for divx encoding to get the type of quality that this xvid guide provides? i have a philips dvp642 dvd player and with the latest firmware it still refuses to play xvid files encoded with this guide, they look awesome on the computer but i want to play them on my dvd player too so i'm looking for a similar guide for divx pro... if you or anyone has a link to one i would greatly appreciate it... thanks
  19. Thrax
    Thrax Yeah, you can use Gordian Knot and use the DiVX codec instead inside the program. You can't load custom quantization matrices, or do much of anything besides enter a proper bitrate, but it's a newbie codec, what do you expect?

    I, however, believe XViD will work on your player - as MPEG4 really is MPEG4 (XViD and DiVX are built on a simple mp4 profile), but you'll need to try disabling BVOP and QPel. QPel doesn't work on almost any set top DVD player.
  20. Unregistered if i disable qpel and/or bvop, will that degrade the quality?
  21. supriokundu
    supriokundu :thumbsup: Hi Thrax,
    I am Suprio, a new member of short-media. First of all I would like to thank you a lot for the excellant article on XviD encoding. You've done a great job! Your article helped me very very much to understand the XviD codec cofiguration, the AutoGK and Gordian Knot(and also the other tools explained there). Your article is easy to understand and at the same time it's very much useful for advanced users. It is the the best tutorial of it's kind on the internet. After reading your article, I've encoded a movie(cry wolf) to XviD with 6ch ac3 audio in matroska, final size is 1GB and have a great quality! I'm also sending two screenshots of original and compressed videos for your review.

    I'm personally very much interested in video compressing and I want to learn it more. You've discussed about the AVISynth in your article, but I think if would have discussed it with much details it would helped a lot. I request you to post another article on that.

    Finally I will thank you again for your great work. If it is possible, please send me your e-mail address to me at supriokundu@gmail.com so that I can contact you and share my feedback on XviD encoding.

    Keep it up!:thumbsup:
  22. Thrax
    Thrax I appreciate the before-and-after screenshots. Not many take the opportunity to do that! I'm sorry for taking so long to get back with you, but I wanted to figure out how to respond.

    The AVISynth section of the article is probably one of the most complicated things that I am personally knowledgeable on to write about. I would, frankly, not know where to begin, and it would be a huge task. I may come back on this task at some time, but AVISynth is far more powerful in encoding DVDs and MPEG2 files. That's where it really shines.

    You can find my instant messengers on the little icons under my user avatar. My email may be in my user profile, which you can get by clicking on my name.
  23. interslice100
    interslice100 Thankyou. This guide was extremely helpful. ;)

    ps. Xvid is better than DivX..

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!