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.
Update 2009-10-19: I’ve re-capture the screenshots and make this tutorial more detailed and easier to follow. I hope this will help most of you guys.
The Reasoning
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 (with good quality) while 26 Episodes fits nicely on one DVD.
What You’ll Need
- XviD Codec – preferably XviD 1.0 (it is used in this guide)
- VirtualDub – This is THE ultimate encoding tool for AVI : )
- Patience
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. You can do this by either dragging the video file right into VirtualDub, or you can use the File -> Open menu to load the video file. Take note that VirtualDub does not support all kinds of video file. Most of the time it will load AVI files and MPEG files, but other formats like MOV (QuickTime), WMV (Windows Media Video) is not supported.

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. Try sliding the slider bar at the bottom of VirtualDub and you can see the preview changes.
Part I – The First Pass
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 the letter “X”), and click the Configure button:

You will be taken to the XviD codec configuration window. Here’s how you configure the Codec:
First off, set the Profile @ Level to Unrestricted.
Then, under Encoding Type, choose Twopass – 1st pass.

Now 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):

Now click on File -> Save as AVI, choose where you would want to save the file (note that the first pass file is only temporary, you will delete it later on after you get your 2nd Pass file).

And now, we wait for it to finish. It will take some time depending on the length of the video, and your computer’s capability (read: processor speed, in general).

Okay, that is the first pass. Let us go for the second pass. 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 remains open, now proceed to the next step)
Getting the Audio size
In order to get the final size exactly how you want it, we need to determine what is the size of the audio portion of the movie.
To do this, 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):

Once the process is completed, check the file size (in bytes) of the WAV file. Keep this figure somewhere. In this example, my WAV file is 39.7 MB (41,634,584 bytes)
The Second-pass
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
For example, we want our file to be exactly 175MB (which is really 183,500,800 bytes, since 1KB = 1024bytes and 1MB = 1024KB)
Final Video Size = 183,500,800 - 41,634,584 (Audio Size) = 141,866,252 bytes
Now divide this figure by 1024 to get the size in Kilobytes (this is what VirtualDub needs). Therefore our Final Video Size in Kilobytes would be:
Final Video Size in KB = 141,866,252 / 1024 = 138,541 Kilobyes
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 (in case you’re lost, this is under Video -> Compression):

(Note : if the filed label is “Target Bitrate” instead, click on it 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. Click OK once you are done.
The encoding process will begin, and you’ll get your encoded file done!

Once the process is complete, you can safely delete the First Pass and Audio files. The Second Pass file is your final output. I hope this helps for those who are interested. Kindly let me know if any part needs further explanation or any errors on this tutorial. Enjoy.





Hi,
It seems that some of the image in this guide is broken. Maybe you can fix it? Thanks!
Fird’s Domain » Blog Archive » Guide: Recording Your Gameplay Videos says:
[...] 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?
Hi,
Thanx for this good tutorial.I was trying to encode one of my .avi file (size is 70mb) to an half of the exact size(merely 30-35mb) with Virtualdub using Xvid codec but always am getting a file size that larger than what i have set for 2nd pass.I have just set the target size as 35mb(35840kb) and target bitrate as 1000 manually as am getting a very low bitrate aft normal second pass. Is there any trick to get the final size merely 30 to 35mb with a bitrate more than 900kbps(being my Original ,avi file’s bitrate is 1700kbps)??
If so, then plz reply me…
Thanks very much for this tutorial — it really helped me complete a task that was absolutely driving me crazy.