How To: encode XviD files to the exact size desired
I thought of writing this guide after my friend Tidus asked me about how to encode certain movie files into smaller size and preferable an exact wanted size. Note that this guide is a mere guideline for those who want to re-encode their video/movie files to fit their wanted size.
Why?
Well, some people (like me) don’t like to waste space on CDs/DVDs when burning. Therefore I would like to have the files fit exactly on the CDs. And after being collecting Animes for a while, I have decided that 4 Episodes fits nicely on a CD-R (with good quality) while 26 Episodes fits nicely on one DVD-R.
Ingredients
- XviD Codec - preferably XviD 1.0 (it is used in this guide)
- VirtualDub - This is THE ultimate encoding tool for AVI : )
- Patience
Getting Started
Well, of course, you will have to install the XviD codec that you have downloaded. As for the VirtualDub, you unzip it to any directory you want and run the program. VirtualDub might give you some notifications/warnings once it is loaded, just click ok on the notices.
On to the first phase
Ok, first off, we are going to load our video file (that is to be encoded) into the VirtualDub (if you can’t think properly, use the File -> Open command)(click to enlarge):

As you can see, there are two preview areas on VirtualDub once you have loaded your video file. On the left is called the Input video preview and the other is Output video preview. Basically, it shows how will your video look like before and after modification (I’m not going to talk about that in this guide, but I might post one about them later). Try and slide the slider bar at the bottom of VirtualDub and you can see your video contents.
Ok let’s get down and dirty. First off, go to the menu Video -> Full Processing Mode:

Then, go to Video -> Compression. This setting will basically let you configure which codec you want your file to be encoded with. Since I am giving tutorial about XviD, choose XviD (usually it’s the bottom-most one, since it begins with ‘X’), and click the “Configure” button:

You will be taken to the XviD codec configuration window. Here’s how you have to configure the Codec:
First off, set the Profile @ Level to Unrestricted:

Next, under Encoding Type, choose Twopass - 1st pass, and then click the more button.

Make sure the Discard 1st Pass checkbox is checked, and hit OK:

Click OK three times to return back to the VirtualDub main window. Now go to the Audio -> Direct Stream Copy (this will directly copy the Audio from the original video):

Once you get that done, click on File -> Save as AVI…, choose where you would want to save the file (not that the first pass file is only temporary, you will delete it later on after you get your 2nd Pass file). Before you click OK, make sure the “Don’t run this job now; add it to job control so I can run it in batch mode” option is checked (this will basically queue your encodes so that you don’t have to wait for it to finish in order to proceed to the next step):

Okay, that is the first pass. Let us go thru the second pass workaround. This need a little bit more work, but don’t worry, nothing an average people can’t do.
(Note : Do not close Virtualdub, and make sure your current video file remained open, now proceed to the next step)
The Second-pass
Okay, before we can proceed to determining what’s the video size required in order to encode the final video, we have to know how big is the audio track first. To do this it’s simple. Make sure Audio -> Direct Stream Copy option is remain checked. Go to File -> Save Wav and save it at a temporary location (the generated file will be removed afterwards anyway):

Ok once the process is completed, check the generated WAV file size (in megabytes). Typical mp3 audio for 25 minutes is about 22.0 Megabytes. Remember this figure.
Now, let’s determine our final video size. To calculate this, you will need to use a very simple math formula:
Final Video Size = (Final Target Size - Audio Size) x 1024 Kilobytes.
Example, we want our file to be exactly 175MB, and our Audio track is 22MB. So our Final Video Size will be :
Final Video Size = (175 - 22) x 1024 = 156,672 Kilobytes.
Ok, once you have this figure jot it down somewhere so that you can refer later on. Let’s resume our Two-pass business.
Back to VirtualDub, again, make sure Audio -> Direct Stream Copy and Video -> Full Processing Mode are both selected. Now, go back to the XviD configuration window, this time, choose Twopass - 2nd pass:

If you noticed, the then-grayed field Target Size (Kbytes) is now available. What you need to do is, to fill this field with the numbers you have calculated earlier:

(Note : if the filed label is “Target Bitrate” instead, click on the button to toggle it to “Target size (Kbytes)”)
Once this is done, click OK two times, to return to VirtualDub main window.
Next, Choose File -> Save as AVI… again and this time give it another name, and make sure the “don’t run this job now; add it to job control so I can run it in batch mode” is checked. Click OK once you are done.
Let’s Start Encoding!
Okay, now that we have gone through all the steps above, its time to let your PC encode the video. This could take a while, so I would suggest you only start the process once you are about to go to bed.
Okay, now click File -> Job control:

You will be taken to the Batch control window. By right, you should have two jobs queued (one for the first pass, and another for the second):

What you need to do now is press the Start button. Let it run till both are finished. Once this is done, you can safely exit VirtualDub, delete the first-pass and the audio file. The second-pass file is your freshly encoded, exactly the size you wanted :)
I hope this helps for those who are interested. Note that if you would like to encode one series of videos that have the same properties, just queue them up accordingly on the Job Control. Make sure you queues the first-pass and second-pass encodings accordingly (they must be right next to each other), and of course, provided that you have enough disk space to hold the output. The audio test only need to be done once, because once you get the Video Final Size figure, you can just keep reusing it (unless if the videos are totally different in their durations).
Kindly let me know if any part needs further explanation or any errors on this tutorial. Enjoy.
Updates
15 April 2007 - Fixed broken image, and replaced all the image to make them consistent


Hi,
It seems that some of the image in this guide is broken. Maybe you can fix it? Thanks!
[...] If you’re into video encoding, you might want to check my Guide: How to encode XviD files to the exact size desired [...]
Fixed the images :)
I am just curious about this, but for some reason whenever I try to extract the wav file when it is in direct stream mode, I get a file size that is humongous, like 491 mb. This is for a video that is only 45 minutes long. Is this abnormal, and I was wondering if I should maybe put it in full compress mode or something before extracting the wav file???
That’s odd. It shouldn’t behave like that. Try compressing it with audio codec that you often use (mp3 normally)?
If the audio is always direct copy, both passes, where does the mp3 audio come from?
What’s the point of extracting the wav?