Past EED rants


Live leaderboard

Poker leaderboard

Voice of EED

Tuesday 2 December 2003

Lurks XviD guide [lurks]

My previous DVD ripping/DivX guide was fairly popular but it seems that it was one of the blogs we vaped when we moved server. Also, I've been doing a fair bit of experimentation with XviD rather than DivX. The reason being that XviD is an open-source MPEG4 codec that is being actively developed, as opposed to DivX which isn't fully MPEG4 compliant and went 8 months without an update. So here's a guide, from scratch, on how to do a wicked DVD rip with XviD complete with a decent soundtrack.
First of all, let's get all of the software. We're going to use GKnot because it installs a lot of it and has a nice GUI which calculates bitrate and does the frame serving stuff for us. This time around we wont be using it for audio. Firstly get the GKnot rippack from Doom9. You should also get the System Pack. You may be able to omit the latter but I've only tested this procedure having that installed. Next up, grab this zip in which I've put Azid and a cmd line LAME so we can do the audio properly. The ones installed by GKnot are old and we need the features of the new versions.
We're obviously also going to need a copy of the XviD codec. Get Koepi's current build.
Now we're ready to go. Slap in a DVD. Run GKnot. On the first tab you've a button to launch DVDDecrypter. Click that, select your drive. Select a a space to save off the VOBs, obviously you'll need bag loads of space on that drive. Then whack the decrypt graphic on it to start the rip and decrypt. You'll have to wait awhile until it's done.
When it's done. On GKnot again, first tab, whack the DVD2AVI button. File/open, select the first VOB that is listed on your hard drive, from the location you ripped them to with DVDDecrypter. It will offer to auto add the rest in the sequence, which is fine by us. DVD2AVI will get bigger and you can now hit F5 to play. In fact, you should do that now. Now we have two cases, if the film is PAL - it will quite often say it is interlaced in the panel on the right when previewing. This is almost always lies. If you really think your DVD is interlaced, wait until it pans and hit escape. If you've got a comb sort of effect on odd/even lines then it's interlaced. Make a mental note of that, we'll have to fix that later.
Now if the DVD is NTSC, things get a bit more tricky. It may be a video framerate DVD or it may be a film framerate DVD. Basically let it play for awhile and DVD2AVI will display a number next to FILM in the preview. If it keeps increasing and goes up over 90% in fairly short order, then it's FILM. In which case go to Video/Field operation and select Forced FILM. Now we need to sort out ripping the audio stream out of the VOBs. To speed the process up a bit and to save on a bit of disk space, we'll just extract what we need which will be Track 1 invariably.
Make sure Audio/Track Number is 1. Make sure Audio/Channel Format is Auto Select. Make sure that Audio/Dolby Digital is set to Demux, which will just Demux track 1 which we have selected. It often defaults to Decode, which we don't want so check this every time.
Now it's just File/Save Project now, save filename into your DVD rip directory - doesn't matter what you call it. It'll take awhile and you'll see some AC3 file appear in the directory and a small D2V file. Sorted.
Back to GKnot. At the bottom left of the GUI, there's an Open button. Bang that and select the D2V file you just saved with DVD2AVI. A preview window will pop up and show a bit from inside the movie.
One of the things we can do with XviD is get it to spend a bunch less of the file on credits where nothing is happening. You know, scrolly ones on a black background kinda thing. You can do this for credits at the start (a bit more rare) and/or credits at the end. If you want to do this, just get out a pen/post-it or whatever and make a note of the start and end frames of the credits at the start and end of the movie. You can do this easily by just dragging the slider in the GKnot preview window, the current frame is displayed in the window title. You don't need to do this step if you're lazy.
Now pop the main GKnot GUI to the front. We need to crop the video so we're only saving the content. Select the third tab called Resolution and hit Autocrop button. You shouldn't really need to do anything else. Now we need to set up the size and bitrate of our rip. The second tab on GKnot is called Bitrate, select that. Now you can enter the size of your rip in CDs, size of CDs and what not. I'll assume you aren't an idiot and can work that out. Select an audio track bitrate of 128kbps and select 1x vbr-mp3 in the overhead calculation pane.
The key thing here is the bits per pixel. We should be shooting for something like 0.20 which gives excellent results. If you go a bit lower than this, it'll go yellow to warn you. You can get away with that in many cases, you'll just see more artifacts. The resolution/compression trade-off is up to you. If the bits per pixel is too low, you'll either need to make the movie bigger or switch to the Resolution tab in GKnot and scale the movie down. Anywhere from 512 to 640 is good. As you drag the slider, you'll see the bits per pixel change. So you can fiddle with these settings to get a compromise you feel happy with.
When you're happy with your choices, hit the Save & Encode button on the GKnot preview window. Now if you're sure your vid is interlaced, enable that on the GUI which has appeared. I recommend the Field Deinterlace option for that. If your vid isn't interlaced the leave that to None. Resize Filter, set to Neutral or Sharp Bicubic. I use the former but others use the latter. Up to you. Hit the Save and Encode button on this and it'll prompt to save an AVS file. Save that in your rip dir with an appropriate name.
Now you're on the Encoding panel of GKnot called the DivX Encoding Control Panel. That's great but we don't care about that because we're gonna do XviD so just close that.
Now in your start menu you've got a Gordian Knot folder and in that there's an Apps sub folder. In there, you'll see VirtualDub. Run that. Now we've got VirtualDub, it might bleat a bit the first time you run it. Just fuck off the bleats and select File/Open and open that AVS file you last saved from GKnot.
In Audio menu in VDub, set to No Audio. In the video menu, select Fast recompress. Then select Compression from the video menu. You'll have a list of codecs. We'll be wanting to select the XviD codec. Hit the configure button. Select from the drop down, 2 Pass - 1st Pass. Then hit the advanced button. Much of the settings here is open to experimentation but I can recommend at least the following is turned on; Enable Lumi-masking, Quarterpel, Global Motion Compensation.
Now go to the Credits tab. Remember that I said to note the start and end of the credits and the beginning and/or the end of the movie? Well here's where you put them. All you need to do is tick the start and/or the end credits option and fill in the start/end frame. If you forgot to write them down from GKnot you can always just exit out of this and find them from within Virtual Dub. I'd leave the other settings.
Now keep pressing OK until you're back to a blank VDub. Select File/Save as AVI and save out firstpass.avi but tick the little box on the file requester that says 'Don't run this job now...'. It'll just add it to the queue so we can run both and leave the PC be while it does the biz.
Now go back to the Video/Compression options. Hit configure on the XviD codec like you did before. This time select '2 Pass - 2nd pass - Int' from the drop down. Now you've got a box to enter video size. You get this number from the GKnot GUI on the Bitrate tab. You've got the Video Size in Kb. So enter that number into the Desired Size box in the XviD codec. You don't need to do anything else, just hit OK and go back to VDub and select File/Save as AVI again. Again ticking the 'Don't run this job now...' box. Name your file finalvid.avi or something descriptive like that.
Hit F4 to open the Job Control. You can just whack Start on this and VDub will fire off doing the first pass and then the second pass. Couple of tips here, firstly if you want to see how your machine is performing you can select 'Show Status Window' from the new 'Dub in progress!' menu that will appear. Secondly, VDub does often slow your machine down when it's doing it's thing however if you run the task manager and select the VDub process, you can right click to turn the priority down to Below Normal and continue using your PC as normal.
Now we're going to do the audio. You can either do that on the same machine or shift it to do on another machine to speed the process up. Earlier I linked a zip which has Lame.exe and Azid.exe in it. To make things easy, copy the AC3 file to wherever you've extracted those and rename it to something easy to type. Do pay attention to the number in front of the ms in the filename though as if it's not 0, we'll need it later.
So now we just do this;
azid.exe -c normal -s stereo -a xxx.ac3 xxx.wav
lame.exe --alt-preset 128 xxx.wav xxx.mp3

You could lower the 128 down as far as 96 if you like but LAME will resample to 32KHz automatically. Still sound fine for movies though. When this is done, you've got yourself an mp3 encoded at the target bitrate using LAME's ABR capability and nicely normalized thanks to Azid. No more quiet soundtracks!
Now when your video is done, you can play it as normal to check it out. You can obviously also listen to the soundtrack as well. Assuming you're happy with both, we just need to glue them together. For this we'll need another version of VitualDub called Nandub, because the original doesn't support muxing VBR MP3s. You'll have this installed as part of GKnot in the start menu/Gordian Knot/Apps folder again. Run it now.
Now all you need to do is File/Open your second pass finished video. Then in the Video menu select 'Direct Stream Copy'. In the Audio menu, select '(VBR) MP3 Audio'. Doing so will open a file requestor and at this point you just pick your finished MP3 file that you made earlier. If there was a funny +30 or -30ms or something like that in the original AC3 filename, select Audio/Interleaving and pop in that number in the 'Delay audio track by' box.
Now you can just File/Save as AVI. It'll save a new file out which will have the video and audio muxed together. It ought to be exactly the size you specified in GKnot. That's it, you're done!


  1. wow..... big thanks for this. I'll comment when I've tried it :)

  2. I've been reading some forums and doing some tests. In conclusion I've decided that it's best to leave Quarterpel and Global Motion Compensation off. Then turn on VHQ mode - I've had damn good results from level 3. Also I've enabled Chroma Motion and enabled B-Frames, so Maximum B-Frames needs raising from -1 to 3. These settings make encoding quite slow but the results are brilliant. I had no trouble fitting a 2 hour widescreen movie scaled to 640 wide into less than 800mb and looking superb.

  3. Just for reference - if you need to get a 48kHz sample down to 44.1kHz, use lame.exe --resample 44.1 :-)

  4. The latest Gordian Knot now has most of the manual steps built-in, like azid and lame. Also it has XviD support built in.