Converting, x264 Encoding Guide

Introduction to Xvids the ape Way

Introduction to Xvids the ape Way

This tutorial assumes you have the following installed on your computer:
AviSynth http://www.mediafire.com/download/kjdzqyz4dyj/AviSynthMT_258.exe, http://www.mediafire.com/download/zt4gzeoo3nk/AviSynthMT_258_INSTALLER.7z
AvsPmod http://avspmod.github.io/
DGIndex
DVD Decrypter or DVDFab
Gordian Knot http://sourceforge.net/projects/gordianknot/
VirtualDub http://sourceforge.net/projects/virtualdub/
VirtualDubMod

All of the above are included in the Gordian Knot except AvsPmod, DVDFab, VirtualDub and maybe AviSynth if I’m not mistaken. I will not go over the installation because that would need another complete tutorial, but if you can’t do the install, you proabaly won’t be able to use the rest of it anyway. So once you’ve got all of these working we can procede.

Since decrypting and copying the DVD is really easy and many times you’ve just downloaded it from some tracker, we’re going to skip that step and go right to the indexing.

This is just an introduction, so it will be a really easy encode.

:idea:It also would be a good idea to read through the entire tutorial at least once before beginning :idea:

STEP 1 Indexing the Source

You will need to open DGIndex:

Click: File > Open > then find your DVD’s folder and open it > open the VIDEO_TS folder and you will see the VOB’s. Pick the ones that correspond to your movie. Start with the first one over 1GB and highlight it and all others in that series. Click Open > OK

The DVD will then open in DGIndex. You can use the slider (1) or the arrow buttons (2) to move through the movie. The brackets (3) can be used to set your start and end points, but usually don’t get used on DVD’s.

Now we can make our .d2v file.
If we Click File > Play the DVD will start to play. If and only if it says ‘Film’ in the Video Type box, you can force film and it saves you a line in your script since it will take care of the IVTC for you.

So now close that video window, click File > Stop and it will stop playing. Now click Video > Field Operations > Forced Film. This will make it be 23.976 fps when we open it in AvsPmod.

NOTE: If it is not at least 99.5% film you will need to use Honor Pulldown Flags on this step. At least one additional line of script will be needed too. TFM().TDecimate() would be used after your source line in AvsPmod

The last thing to do in DGIndex is to make the .d2v
Click File > Save Project, name it and send it to a folder where you can find it later.

Now click Save and it will index the movie for you and extract your audios.

STEP 2 Writing the script

You will need to open AvsPmod.

Once its open you want to type in your script.  It starts with opening your source by using the .d2v file created in DGIndex. So put this line into your AvsPmod where xxx = the path to your .d2v file and yyy = the name of your .d2v file:

MPEG2Source(“C:\xxx\yyy.d2v”, cpu=0)

Then hit f5 to refresh it. Any time you change your script you will need to hit f5 to see how your changes look.

There’s a lot of interesting information on you AvsPmod. It tells you what frame you are on, how many frames there are total, the fps, the width and height, and the AR. You can see that since this is an NTSC DVD that the dimensions are 720×480 before we do cropping and resizing. You never want to be bigger than that.

This DVD is a really good source, so considering its got no Telecine, no Interlace, and needs no filtering, all we have to do is crop and set the AR.

To crop, all you need to do is right click in the view box and click Crop Editor. Then just use the up and down arrows  to do your crop. When you have gotten rid of all matte, hit Apply. Hitting Apply does the same thing as f5, so you don’t need to do f5 this time to view your script changes.

To make sure you got it all, just right click again Zoom > 400% and you can easily examine all edges for any matte you may have missed. I got it all, so no need to do any more cropping.

Now its time to do the AR. Using another script (see below) I have determined that AR is 1.8:1. When working with xvid you must keep it mod 16. This means that the height and width must be divisible by 16. The width will be the deciding factor here. It can be either 720 if we slightly upscale it, or 704. Since we only cropped 4 and 716 is closer to 720 than 704, we’ll use 720 as the width in this example. To make it be 1.8:1, the width will have to be 1.8 times larger than the height. 720/1.8 = 400. 400 is also mod 16 so it will work for this xvid just fine.

Its time to set the AR with another line of script. There are a few resizers, but Spline36Resize is a good all purpose one. To use it you add this line to your script:

Spline36Resize(720,400)

In case you didn’t figure it out, the 720 and 400 inside the parenthesis is the width and height for the resize.

After you hit f5, it will look like this:

You can see that the Width, height, AR, and fps are all what they should be. So now we save the script and start testing to see what the size will be. Save the script by clicking File > Save Script, naming it the same as the .d2v and clicking Save.

STEP 3, Compression Testing

This is where the Gordian Knot comes in. Time to open it up. once its open you’ll have to open your .d2v in it by clicking the Open button in the bottom left and finding your .d2v again.

When you open it another box opens with another viewscreen. Now we go to the Bitrate tab and put in all the audios. Then we go to the Resolution tab and set your width, height, and AR. Make sure the number of frames and fps match your AvsPmod.

That’s all you have to do there, go to the viewer window and hit Save & Encode on the bottom left. Another box will pop up that says save avs, but you don’t want to save anything, just run the test. so where it says Compressibility Check, click the Use (1). We’re going to dabble with the matrices in the future, but for now you’ll just work with the size. So go ahead and click the Edit button (2).

You’ll get the Avisynth Comp.test Frameserver window. That’s the script that its going to run the test on, but its not the script we made. So what you have to do is edit theirs into yours by deleting all that text all the way down to #COMPRESSIBILITY CHECK and replacing it with your script. Either copy your script from AvsPmod, or open it with Notepad and copy it, then past your script in. When you do that it will look like this:

Then just press the Comp Check button (1), click OK, and it will open VirtualDubMod and run your test. This should take about 10 or 15 minutes in this case. It could be much longer with complicated filtering though. VirtualDubMod is now doing an encode on 5% of source and analyzing it to see how compressible it is. You need to do this because different factors in the quality and content of a movie can alter the size needed to make your best encode. Its a service to everyone to make the best possible encode :)

After its done it will shut itself off and you can go back to your Gordian Knot and see the results. We are shooting for 80% to 100%. If its lower than 80% you will need to make your size bigger. If its over 100% you will need to make it smaller.

So what size should we make this? There is a thing called AFR that is very well explained by ShadyGuy in a CG tutorial.

Quote:
The term ‘AFR’ stands for Advanced Filesize Regulation; it’s a set of criteria which can be employed to accomplish DVDR-sized rips. The big difference about AFRs when compared to normal movie rips is you get the highest resolution and bitrate for the smallest possible size. It’s all about maintaining source transparency while keeping filesize as small as possible; image quality is retained to almost 100% and sound quality is identical to the original source

What are the specific AFR sizes?
1/6 DVDR: 0.73 GB (0743 MB or up to 0747 MB with subs)
1/4 DVDR: 1.09 GB (1116 MB or up to 1120 MB with subs)
1/3 DVDR: 1.46 GB (1490 MB or up to 1494 MB with subs)
1/2 DVDR: 2.19 GB (2236 MB or up to 2241 MB with subs)
2/3 DVDR: 2.92 GB (2984 MB or up to 2988 MB with subs)
3/4 DVDR: 3.28 GB (3358 MB or up to 3362 MB with subs)
1/1 DVDR: 4.37 GB (4478 MB or up to 4482 MB with subs)

There is also 1 CD size that he did not list 700 MB

Generally xvids over 90 minutes need to be 1.46 GB and under 1.09 GB so we’ll try 1.09 GB first. You will want to go to the Bitrate tab (1), make sure all your audios are entered (2), and set your Total File Size (3) to 1116 MB to 1120 MB (1116 MB to 1120 MB = 1.09 GB). I usually use 1119 MB myself as you will see below.

If the # next to the Load button (4) is between 80 and 100, your size is correct. If its bigger than 100 you will need to put the 1/6 DVDR or 1 CD size in the Total File Size box (3). If its smaller than 80, you will need to use the 1/3 DVDR or in extreme cases the 1/2 DVDR size. When you’ve found your size you can open VirtualDub, but don’t close Gordian Knot yet.

STEP 4: Encoding

Open VirtualDub, then find your script in its folder and drag it onto VirtualDub.

Click Video it should have Full Processing Mode ticked, if not tick it, then click Compression and pick Xvid MPEG-4 Codec from the dropdown in the left window then click OK.

Now click Video > Compression > Configure and the Xvid Configuration window opens. This is where we set the passes so you will click the arrow next to Encoding type, pick Twopass – 1st pass and click OK > OK > File > Queue Batch Operation > Save as AVI > Save. Your first pass is set.

We’ll do the same thing again to set the second pass except we have to set the size here. You will now need the data from Gordian knot. This time do Video > Compression > Configure > Twopass – 2nd Pass > calc… This is where I’ll put in the data from Gordian Knot. My total audio size was 546642 kb, and the target size is 1145856 kb so I enter these and the time and frames per second. When finished click OK > OK > OK > File > Queue Batch Operation > Save as AVI > Save. Your second pass is set. You can close Gordian Knot and AvsPmod now if you like.

Its time to start your encode. Press the f4 button and your VirtualDub Job Control window appears. Choose your first pass and hit Start. It will run both passes for you so VirtualDub will do all the work. You’re done now until the encode finishes. Depending on your computer and the amount of filtering this could take anywhere from a couple hours to several days. When it finishes we have to add the audio using VirtualDubMod. Close VirtualDub when your encode is complete.

STEP 5: Adding audio

Open VirtualDubMod. Click File > Open Video file, find your freshly made Xvid and choose it > click Open.
When its loaded, click Video > Direct Stream Copy. Direct Stream Copy simply copies what you put in it without changing anything.

Next we have to tell it which audios to add so click Streams > Stream List > Add > pick your audio > Open.
If you have more than one audio, you will have to repeat this step for each one.

These are the audios that were made in the DGIndex step. The streams will now appear in the available streams box. If you are happy with them, click OK.

Now its time to make the finished product. Click File > Save As > put in a file name (I always use name of the video I opened and add the tracker) > Save.
It will start adding the audios to the video. This should only take a minute or so and concludes the process.

STEP 6: Watch and Upload

All that’s left to do now is watch your entire video to make sure there were no errors anywhere and upload it where ever you can so the world can benefit from your work :)

Important things to remember

Here are some important things to remember when encoding to Xvid:

1) Your dimensions always need to be in mod 16

2) Since Xvid is SD, your width should never be greater than 720 and you height should never be greater than 480 for NTSC, or 576 for PAL.

3) All matte should be cropped from all four sides.

4) Total file size should be AFR standard whenever possible.

5) The fps size will almost always be 23.976 fps. There are exceptions to this such as badly blended sources, variable bit rate sources, or movies shot straight to video. If you are dealing with newer DVD’s you will probably never see one of these.

6) Be sure to use correct AR. Here are some common maximum AR’s:
Full Screen NTSC 4:3 = 640 x 480
PAL  4:3 = 720 x 540
Wide Screen NTSC or PAL 1.80:1 = 720 x 400
NTSC or PAL 1.85:1 = 720 x 384
Cinematic Wide Screen NTSC or PAL 2.35:1 = 720 x 304

The script I mentioned above to determine AR is:

Quote:
#DON’T FORGET TO CHANGE THE FORMAT AND WIDE ACCORDINGLY!!!!!!!!!!!!!!!!!!!!!!!!!!

avsfile = “C:\Users\Public\unknown\encode.name.here.avs” # Encoding script
format = 1 # 1=NTSC, 0=PAL
wide = 1 # 1=Widescreen 16:9, 0=Full screen 4:3
#########################
ITU = (format==1?10:12)/11.0*(wide==1?4.0/3:1)
SARs = “”””12:11″,”16:11″,”10:11″,”40:33″,”16:15″,”64:45″,”8:9″,”32:27″”””
ITUprof = “”+(wide==1?”ANAMORPHIC “:””)+(format==1?”NTSC”:”PAL”)
i=import(avsfile).converttorgb
i
ab = round(height*(sqrt(45.0/44)-1))
a = spline36resize(round(width*ITU),height)
a = a.addborders(0,floor(ab/2.0),0,ceil(ab/2.0))
bb = width(a)-round(width*ITU/sqrt(45.0/44))
b = spline36resize(round(width*ITU/sqrt(45.0/44)),height+ab)
b = b.addborders(floor(bb/2.0),0,ceil(bb/2.0),0)
interleave(a,b)
scriptclip(“””subtitle(“Playback Resolution: “+\
string(round(width(i)*ITU*pow(44.0/45,current_frame%2)))+”x”+string(height(i))+\
“\n”+ITUprof+(current_frame%2==1?” NON-ITU”:””)+\
“\nx264 –sar “+eval(“select(2*format+wide+current_frame%2*4,”+SARs+”)”),lsp=0)”””)

#This script is functioning with a script in my C:\Users\Public\unknown folder called encode.name.here.avs. You would have to change the paths to suit your setup. I do my analysis add tfm().tdecimate() or whatever is needed, crop and save

Just open a new tab in AvsPmod and paste this script in it. Then save your script before you set the AR, replace ‘encode.name.here’ in the new tab with your script name, do 1 or 0 for NTSC or PAL, 1 or 0 for Wide or Full screen, and hit f5. The AR appears at the bottom right. 1.79:1 in this case which will I rounded up to 1.8:1.

That concludes this introduction. I hope it helps you to make great Xvids!

Standard

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.