Log in

View Full Version : Quick XviD guide


-h
28th January 2002, 11:47
This is a preliminary guide, mainly a merger of the myriad posts here, on how to use XviD to perform 2-pass encoding. It's very bare-bones - you should already know how to rip, how to crop and resize, how to encode and mux audio, etc. All these things are explained in Doom9's guides.

There are a couple of ways to encode using XviD and VirtualDub, and they happen to be very similar to Nandub with GKnot. While you can use XviD's internal 2-pass support, it doesn't allow any of the extra features found in GKnot like credits. If you prefer the options GKnot gives you, the only difference between XviD and Nandub .stats editing is to disable "Luma correction" and "Motion correction".

Step by step:

1) Basic codec setup

The Configuration dialog consists of three tabs:

- Main - All you should have to configure here is the "Quantization type". This tells the codec how to go about removing information from the picture during compression - the MPEG quantizer is sharper and slightly slower, whereas H.263 smooths the picture more. DivX 4.x and DivX 3.11 use H.263, and don't let you choose this option. The "Motion search precision" option governs how accurately the codec will match similarities between frames - the slower the choice, the better the compression. It is set to 5 by default, because 6 is much slower, but less than 1% better.

- Advanced - The CBR options are only used in "1 Pass - CBR" mode, so you can leave them alone. The minimum and maximum quantizers should be left to 1 and 31, as they shouldn't need to be constrained in 2-pass mode. The "Luminance masking" option makes the codec use more compression in areas that are dark or light, as these are harder for the eye to perceive comrpession artifacts in. This allows, in theory, the same perceived quality in a smaller file. The "Discard encoded bitstream on first pass" option should be left enabled, unless you want the huge resulting file from the first pass.

- CPU - XviD's CPU detection will automatically detect what instructions your CPU supports - if the codec crashes, you should definitely contact the developers with a report so it can be fixed.

2) First pass

You should have already performed cropping, resizing and/or filters on your video source by now. It is assumed you're frameserving with Avisynth.

Open the .avs script in VirtualDub. From the "Video" menu, choose "Fast Recompress" to avoid unnecessary color conversions. In the codec's "Main" tab, set the Mode to "2 Pass - 1st Pass", and specify the .stats file you wish to save to. In the "Advanced" tab, make sure that "Luminance Masking" is unchecked - it should never be enabled for the first pass.

If you are creating a 1-CD rip, you should set the "Motion Search Precision" to 6, to squeeze everything you can out of the codec. The "Quantization type" should be set to H.263, as it generally has fewer blocking artifacts with the high quantizers a 1-CD rip generates.

For a 2-CD rip, it is recommended that you keep the Search Precision at 5. Quantization type should be set to MPEG for sharper images.

3) Calculating the .stats file for 2nd pass

If you do not wish to use Gordian Knot to edit your .stats file, you can depend on XviD's internal curve mod and skip this step.

In Gordian Knot, open your .stats file from the 1st pass (its location and name are specified in the 1st pass stats file text box in the main tab of the codec's configuration dialogue). The basic things to do here are to enter the size you want your final encoded AVI to have (it doesn't matter which codec you choose - GKnot calculates the bitrate-curve based on framesizes, not on bitrate), to enter a size or bitrate for the corresponding audio-file/stream, and to uncheck the "Luminance correction" and "Motion correction" options in the stats-editor tab. You should also encode your credits at a lower bitrate. Then click on "Calculate". If you don't want to make any manual corrections, click on "Save", and you have your .stats file for your customised second pass.

If you want to do anything else with GKnot, you should consult Doom9's guides, or GKnot's integrated help.

4) Second pass

If you're aiming for a 1-CD rip, it's advised to enable Luminance Masking from the advanced tab for the second pass - for such low target bitrates, it will do more good than harm.

If you performed a .stats mod in GKnot, set XviD's mode to "2 Pass - 2nd Pass Ext." The 2nd pass stats file text box will now be enabled, and you can select the .stats file you saved from GKnot. That's all you have to do!

If you did not use GKnot for the .stats mod, set XviD's mode to "2 Pass - 2nd Pass Int." Enter the desired size of the video stream in the "Desired file size" text box - remember, this excludes the size of the audio stream(s), and is measured in Kilobytes. Entering 573440 will give an output avi of 560 MB.

Now save your avi.

If you have suggestions for this guide, contact -h or Teegedeck.

Apu
28th January 2002, 11:52
nice tutorial so far, but for me there is one question left. What does Xvid assumes as 1kbit? 1024 bit as DivX3 or 1000 bit as DivX4? this is important for calculating the bitrate in GKnot.

-h
28th January 2002, 12:01
XviD assumes 1 kilobit = 1000 bits, as per the MPEG4 spec.

Do you set a bitrate or a file size in gknot? I didn't think it'd matter honestly :) XviD's internal curve mod never needs to think about bits/kilobit - all the values in .stats files are in bytes.

-h

Apu
28th January 2002, 12:21
Do you set a bitrate or a file size in gknot?

I set a filesize, but I did not know whether GKnot changes the .stats depending on the setted filesize or if it changes ist depending on the calculated bitrate or whatever...

but thanks for answering anyways

Teegedeck
28th January 2002, 15:36
Originally posted by Apu


I set a filesize, but I did not know whether GKnot changes the .stats depending on the setted filesize or if it changes ist depending on the calculated bitrate or whatever...

but thanks for answering anyways

I got identical filesizes regardless of choosing DivX3.11 or DivX4.xx as codec - so I guess GKnot calculates based only on filesize. But you are free to do more tests, I only did this single one.

Apu
28th January 2002, 17:13
But you are free to do more tests, I only did this single one

I did some tests with trailers of full metal jacket and the negotiator and one captured music clip. You are right, they're identical.

MaTTeR
28th January 2002, 17:39
Thanks for the quick guide -h. It was very helpful in getting me up and running.

Question- Has anyone tried using the temporal smoother filter in AVS yet? I've been using it with DivX3 for awhile now with excellent results. However, it appears that I might not need to use it with XviD as it does a much better job.

MaTTeR
29th January 2002, 07:50
Thought I'd pass this thread along from the videocoding forum.

http://www.xvid.org/index.php?section=Forum

Basically in this thread suxen_drol states the file size will be more predictable if you select Div3 as your codec within Gknot. Anyone had a problem when selecting Div4?

Selur
29th January 2002, 09:26
Hoi, just wanted to let u know I wrote a little step-by-step guide (for Xvid with GKnot) in german an posted it in the german Flaskmpeg Forum:
http://www.boardy.de/showthread.php3?threadid=33852474

May be some of the german readers might want to have a look at it ;)
(hope u like it, if not don't flame me it's the way I encode,... and not a "this is the wy u have to...")

Cu Selur

Ps.: Just discovered the 'Alternative codecs' section here at doom9 :devil:

Apu
29th January 2002, 11:19
Anyone had a problem when selecting Div4?

no, I ran another hardcore test this night on this issue with
"Stigmata". In both cases the movie became 734.715.904 Bytes.

Ripe73
29th January 2002, 11:59
HI!
Doom9 says we should use Luminance masking for second pass only for 1cd rip will there be a difference if i use it in both passes?
http://rilanparty.com/vbb/showthread.php?s=&threadid=14750&pagenumber=2

BTW i think Xvid is good because it give the same quality as DivX 3.11 and i dont need the Antishit---->faster encoding:)

-h
29th January 2002, 12:12
You don't want to use lumi masking in both passes - it will amplify the effects of the increased compression to levels that will most likely be obvious. Best to use it only in the second pass.

-h

Ripe73
30th January 2002, 23:15
HI!
I try to do the 2 passes in a row and when i start Virtual Dub 1_4_7 in jobcontrol it crash.
*Load *.avs
*Fast recompress
*2 pass first pass MPEG 5-very high
*save first pass add to jobcontrol

*2pass second pass int.
*set final videosize
*save second pass add to jobcontrol

*start jobcontrol--->crash

no luminance masking

Thanks

sierrafoxtrot
31st January 2002, 00:14
@ripe73: use Vdub 1.4.8 :), 1.4.7 will not allow for job processing. thank Killah for the tip (see other thread in this forum)

rui
31st January 2002, 17:43
Originally posted by sierrafoxtrot
@ripe73: use Vdub 1.4.8 :), 1.4.7 will not allow for job processing. thank Killah for the tip (see other thread in this forum)

This was a great tip! Thanks :)

Peters
2nd February 2002, 00:22
Originally posted by -h
You don't want to use lumi masking in both passes - it will amplify the effects of the increased compression to levels that will most likely be obvious. Best to use it only in the second pass.

-h

As the opposite, for one CD Rip (say a 100 mn movie long) I noticed some bad compression on dark scenes if luma is used (2nd pass)
Unchecking luma makes these scenes better.

But of course for the same file size, we have to take the bits somewhere. So do we have to pay attention to the general light of the movie (dark movie, no luma at all) ?

Thank's

Ripe73
14th February 2002, 15:34
HI!

Can someone explain the 2pass Debugfunctions I-frame min and max and when its best to use the Smooth q.box and if i use Smooth q.box should i use it for both passes?

Thanks

rui
14th February 2002, 15:43
Good question :)

-h
15th February 2002, 00:07
The I-frame quantization settings restrict the quantizers that may be used for I-frames (key frames). If you set the min and max to 2 and 2, then the keyframes in your movies will be high quality and large in size.

Now, because of the way the 2-pass "bit bucket" works, setting the I-frames to artificially low quantizers will result in the P-frames following it to have extremely high quantizers - such a quick jump will produce ugly output. So, the "Smooth quantizers" checkbox will prevent the quantizer from jumping too far between subsequent frames.

If you're going to mess with the I-frame quantizers, you should check that box.

-h

rui
15th February 2002, 09:43
O.k, understood.
Thanks ;)

Ripe73
15th February 2002, 09:46
Okay thanks its like min and max keyframequality i Nandub but the smoothq. i dont need to check that box for the first pass ,right?

Teegedeck
15th February 2002, 11:33
how did the guide get unstuck? trying to fix this...

-h
15th February 2002, 12:47
how did the guide get unstuck? trying to fix this...

I was trying to unstick it, seeing as Doom9's guide was prettier. After a few tries at unsticking it, and refreshing the forum had it still stuck, I gave up :)

Guess it somehow kicked in eventually. Ah well.

-h

Doom9
15th February 2002, 13:23
I unstuck the guide since we have a more illustrative guide... text only guide can be a good basis but I think most of the people prefer a nice html guide with images... plus I want the Q&A to be on top. so if you have no objection let's unstick it again

-h
15th February 2002, 13:40
It was actually telling me "the post has been unstuck", but it stayed there regardless. It's much better having the single Q&A there, any new information on settings etc. can be merged in there instead of floating around and getting out of sync in guides.

-h