Optimal Encoding Bitrates for .avi (dvix/xvid) Video Files
CCE SP (a trial version will do)
AVISynth 2.5 (latest version)
An MPEG2 Encoder of your choice (if you are not going to use CCE)
What this guide is for: To find the OPTIMAL bitrate for encoding AVI's to MPEG2.
OK, you have an avi (or multiple avi's like TV episodes) which you want to put on a DVD without wasting space or quality......how do you do it? A bitrate calculator WILL NOT HELP as that only it gives you a pre-set answer depending on the length of the video to be encoded (plus audio bitrates).....maybe you can guess..yes thats a good way if you've a fair idea of what you are doing ...maybe you follow the crowd and go by one of those 'for this bitrate use this resolution'....(I wont say what I really think of those 'bitrate X resolution' charts) ...so how DO we find the OPTIMAL BITRATE?
The answer is to use CCE SP's buit in OPV (one pass vbr) mode which will self adjust itself to the 'compressibility' of any given AVI (within set parameters or 'Q') and therefore set its own optimal bitrate.
Once you have the bitrate, you can then use the found figure in your usual MPEG2 encoder, or for CCE users, use it direct in either OPV or multipass vbr modes (though you dont ALWAYS get better quality using multipass over opv) or even CBR mode.
So lets get started.
First up fire up FITCD and load your avi from the lower screens SOURCE (folder icon) button.
REMEMBER FITCD defaults to NTSC (so there are no NTSC buttons) and avi's are always 1:1 MONITOR (in our case anyway) nor are they ever ANOMORPHIC so the left ANOMORPHIC tab should NEVER be checked.Select ACCURATE in the CROP tab.
Now on the right select the DESTINATION tab and select 720X480 (or 576 if the avi is PAL..which will also be auto checked on the avi source side). In this first example the avi movie has an ASPECT RATIO of 2.3529:1 so to fill the screen up we want to select ANOMORPHIC on the RIGHT and then we need RESIZE (why resize?, because nearly all TV's overscan so reducing the visible TV image AND it will also cut down slightly the bitrate required).Also notice that because we have selected ANOMORPHIC the vertical resolution of the output file is INCREASED.
So what do we RESIZE to?, well I suggest somewhere between 640 and 688 wide and use WHICHEVER size is CLOSEST to the originals AR.
Below is another example but this time from a 1.33AR source avi.
Now because we are using CCE we also want to ensure the AVS script that we are about to make is compatable with CCE..so check the YUY2-OUTPUT box. One final thing to do DELETE this line:
So highlight and delete this line only (AFTER everything else is correct). FITCD now looks like this:
Save (SAVE SCRIPT TAB) the AVS file to a location of your choice (after giving it a simple name).
Now we need create a 'test' avs file to allow CCE to encode a small percentage of the full avi so we add one of these lines:
To select a percentage sample range of the avi to give an 'across the board' sample of encoding bitrates....the higher the sample % the more accurate the final expected file size, but the longer the opv will take to encode.
COPY AND PASTE THE 'SelectRangeEvery(XXX,XX)' into your AVSscript and SAVE the .avs as a new script by adding '.test' after the file name but BEFORE the .avs extension (as you dont want to overwrite the original AVSscript), I will be using the 2% script line:
eg: 'mymovie.avi.avs' will become 'mymovie.test.avi.avs'
For 1% of avi add this line to your AVS script (filesize X 100):
For 2% of avi add this line to your AVS script (filesize X 50):
For 4% of avi add this line to your AVS script (filesize X 25):
For 5% of avi add this line to your AVS script (filesize x 20):
Once your OPV (one pass vbr) has been encoded (to 'yourfile' .mpv) multiply its filesize by the factor that suits the % sample used. But first to the encoder.
Load CCE SP and click on the TEMPLATE tab. Double click on a template and set it up thus (i'm using CCE2.62 here so your interface may look slightly different but the results should be the same).You want ONE PASS VBR selected and a Q value of 22
First create a TEMPLATE by altering the information to this (for later CCE versions hunt around for the checkboxes):
NOTE we are NOT doing AUDIO!
Ensure you always set the TIMECODE to 00.00.00.00
Set the DAR to either 4:3 if you DID NOT select ANOMORPHIC in FITCD... or.... 16:9 if you
DID select ANOMORPHIC in FITCD.
When done ADD the template to CCE by pressing the ADD button and give it a name before pressing ADD (like OPV.Q22).
Just a few lines about the Q value...as the Q value gets smaller MORE bitrate is given to the mpeg2 (and a sharper image...sometimes too sharp..artefacted) and as the Q value gets larger the bitrate becomes LESS (and the image softens)...what you want is a happy medium..which is why I use Q22 in this instance (YOU decide on a Q value thats suits your eyes..this is only a guide not a statute law)...but for your benefit I have also done the same file at Q10 and Q35 (all animations at 4:3).
Ok you should now have CCE set up with the OPV template so now we need to ADD the
Right click in the big white box on CCE and select ADD
You should now have something like this:
Now press ENCODE
CCE will ask you if you want save changes to no-name select YES and create an ECL file (call it something simple A1.ECL).
The encoding starts..and finishes in a couple of minutes.
So we now have a .mpv (.m2v) file of 2% the size of what the full file size would be.
From the .mpv we can determine the final video size and the bitrate used.
How to calculate the final mpv/mpv file size.
Locate your saved 'mymovie.mpv' and underneath (dont click on it) should be the file size in kb....multiply this figure with your percentage multiplication factor (X 50 for 2% as used in this example).This can also be done by selecting properties and using either the size in MB or the size in bytes...just remember which 'method' you are using)
So in my three 4:3 animation examples, I have found the .test file sizes (then multiplied by 50 my 2% multiplication factor) to give the EXPECTED completed size of each FULL movie encode (obviously without AUDIO) :
Q10 = 11685kb X 50 = 584250kb or 584mb or 0.584gig final size
Q22 = 8112kb X 50 = 405600kb or 405mb or 0.4gig final size
Q35 = 6386kb X 50 = 319300kb or 319mb or 0.32gig final size
(the original avi's properties are: 512 X 384 res, 23.976fps, 32422frames a runtime of 22min 32secs, 720kbs and a file size [inc audio] of 138mb).
You can see that from the filesize alone that the smaller the Q value the higher the bitrate used and ultimately the end filesize.....so find a Q value your are happy to use that doesnt give too soft a picture (a high Q value and low bitrate.. or.. too sharp/artefacted picture from a low Q value and a high bitrate)..I'm happy with Q22 but it does vary from avi to avi....and sometimes you just cant tell any difference really.
Now the fun bit...or not...use a calculator!
Now to Calculate the OPTIMAL bitrate as decided by CCE's OPV from your test avi's mpv file for use in the full encode using your mpeg encoder (CCE, TMPG, MainConcept,ProCoder etc).....but obviously if you have CCE you could jut use OPV mode for the full encode (if your happy with the results from the test) and it will take around a third of the time of doing a 2pass+vaf.
OK, here goes:
a) you need the ORIGINAL avi's total number of frames, open the original avi in VirtualDubMod (or the .avs script for the FULL movie not the test) and then open File Information. In my examples above its 32422 frames.
b) the fps of the avi (again from VDM's File Info) in this case 23.976 fps.
c)Now divide 'a' (32422) by 'b' (23.976) and the result is 32422/23.976 = 1352.26 which we will call 'c'
d) use the mutiplication factor of the test percentage used (in this case 50...lets call it 'd').
e) we need the final size in BYTES of the TEST avi...right click on the test.mpv file> select properties> and write down the size in BYTES..for this example we will use the Q22 example...8,306,220 BYTES which we will call 'e'.
So the calcualtion you want is:
e X d X 8 divided by 1000 divided by c
8306220*50*8/1000/1352.6 = 2456kbs
Now that you have the (ave) bitrate for the mpeg2 you can use that as the average bitrate for your encoder. Also note that if your doing a multipass then you could probably go 10-15% less than the CALCULATED BITRATE.....for max bitrate use circa 6000..if doing a CBR then I would use a value of approx 1.5X
Heres the pics of the original avi, the avi script and the three Q values I used:
Original AVI at full size:
The AVISynth .avs script
And for the 16:9 movie as used in the first example of FITCD:
Original full size avi:
Original avs script:
And the Q22.mpv output
If you want to know this movie came out at 1.65gigs without the audio..not bad eh for a 1hr 45min runtime...ave bitrate was only..wait for it..2252kbs!!
Hope you find this guide useful!!
PS. The animation still sizes are slightly reduced (72dpi from 96dpi) as jpeg compression to less than 50kb added artefacts that are NOT present in the originals....but I can tell you the difference between Q10, Q22 and Q35 is not worth mentioning for these avi's... if anything the Q10 look WORSE on close inspection due to their HIGHER bitrates which no doubt is the cause of a lot of problems with encoders as most people have been given so much false information over the years: that is to say HIGH BITRATES = better quality...which is simply NOT true (when converting compressed avi's/divx/xvids to full size DVD)...so just get over it...try it, use it and wave goodbye to the BITRATE BLUES.
For a trial version of CCE SP try here (its fully functional but adds a logo to the encodes):
+ Reply to Thread
Results 1 to 23 of 23
2.2Mb/s is ENTIRELY INSUFFICIENT for 720x480 encodes. The WILL BE, without a doubt, artifacts. Even DVB, one of the highest compressed MPEG formats, does not skimp this much. Even SVCD is already pushing the quality envelope at a meager 2.0-2.5 Mb/s VBR at 480x480. There is insuffiecient bitrate allocation in this guide.
My source is 352x240.
I selected 720x480, selected anamorphic on the right, and it squashes the video to 588x480.
Resize allows only some other, even worse, AR's.
I did a 2% Q22, and my final mpeg is only going to be 54MB, yet it's a 1:33 movie that fitcd only "sees" as 46 minutes.
I have encoded this avi in tmpgenc (frameserved from virtualdub), Mainconcept, WinAVI, and VSO with no trouble.
Virtualdub (and mod) detects no errors.
You have checked:
Add sequence end code.
Linear quantizer scale.
Zigzag scanning order.
Why would I want these? They're not checked by default.
Linear quantizer scale is a toss up , dvds are really non-Linear but many report getting better quality selecting Linear ...
end code is normal for dvd authoring apps. if you are using multiple clips in a single timeline you might not want to check this except for the last one..
progressive for film source .
zigzag for progressive source..."Each problem that I solved became a rule which served afterwards to solve other problems." - Rene Descartes (1596-1650)
Originally Posted by lordsmurf
I've written bitrate allocation charts that have been re-published by others and examined by some pros. (In fact, a very popular software has STOLEN my information, even re-used terms I made up, and never gave me any notice or credit. At least the information is getting out like it needs to!) So sorry, not budging an inch. The allocation is super-insufficient here. I never made SVCD's by choice, only done a few, allocation is not great (actually prefer CVD instead when allowed, slightly better allocation). Hard to ignore the math here.
Originally Posted by reboot
Originally Posted by monzie
I use my old-school M$ Calculator and calculate myself the most optimal bitrate for my set video length, then I tell CCE to do a one-pass VBR (actually 2 passes because the vaf or whatev doesn't 'count') w/ 0 VBR bias and average of whatever my number is, minimum of 0 (altho some may say that they want something higher for minimum like 300) and maximum of 9800 - audiorate rounded down to the nearest hundred (i.e. for a 448kbps AC3 stream I do 9800 - 448 = 9352, truncate to 9300). CCE is good about staying in bounds. Also, this way I can tell it where I have end credits if I'm backing up a DVD, further saving myself bitrate which is then distributed to the rest of the file.
However, if exactness in bitrate is not critical (like a home video) then I would go w/ one-pass vbr w/ a low quantizer scale just like u did.
Originally Posted by lordsmurf
that makes no sense"Each problem that I solved became a rule which served afterwards to solve other problems." - Rene Descartes (1596-1650)
Originally Posted by BJ_M
It's cute how people try to sound important by using big words in
complex sentences. Even moreso when it's jibberish.
One more thought: LANCZOS is NOT an "always better" setting.
Sometimes bicubic will look better. It's all a matter of experimentation.
We're not trying to bash you.
We're trying to give you some better info for the guide.
Guides are supposed to help people, not set them down a path
that confuses them more, and opens them up to potential
problems(in this case, artifacts from insufficient bitrate allocation).
Even if you had professional hardware encoders, you'd experience
GOP deterioration and macroblocks with such a small bitrate.
Even on a 20" old tv set, this would be easily noticed.
'optimal bitrates via a calculator' how?
'That makes no sense' What doesnt?
Originally Posted by lordsmurf
Your not crawling out of this smurfy...... you belittling little pixie you.
Just try it..... THEN be a critic......whats stopping you....?
Having seen LordSmurf's site and read many of his posts, I accept that he is credentialled and experienced. Can you present your credentials, Monzie, so that I can get an understanding of the basis of your bad-mouthing an industry-experienced contributor.Read my blog here.
OK, its a new day so lets get this guide back on track...and i'll try my hardest not to shoot anyone (especially LordSmurf...as I know he's a great bloke who helps an awful lot of people...so lets leave at that eh?...and no, I'm no expert just a keen amatuer who like experimenting).
I suppose what I really want is some constructive critism from people who have TRIED using the OPV method..and feedback regarding their findings.
If you want more information on OPV bitrate settings AND an Excel spreadsheet (use OpenOffice if you dont have Excel) which will calculate the average bitrate for you from your percentage sample, go here (and look for the KBPS-frm-filesize link):
OK, heres a few results from another xvid..of a movie that isn't one of the Matrix trilogy.......lets call it Equi....I chose this because unlike the other examples it has a high action sequence.
The actual avi
Same scene encodedfrom the Q22 mpv
Encoded from the Q22 mpv
Encoded from the Q22 mpv
Now when I did a 2% sample on this avi the calculated bitrate returned at 2107kbs.....which i thought was rather low.....so I used a 5% sample and that returned at 2157kbs...I dont have Bitrate Viewer so I dont know what its maxing at but my 5% test file has a size of 83,636kb X 25 = 2.1gig (without audio) for a 1hr 45min movie. If i had used the Bitrate Calculator (using 192kbs audio) it would return an ave bitrate of 5612...or 2.6 times higher than required.
The original xvid (note... I'm talking compressed avi's here) has a rather low 777kbs (to squeeze it onto a single CD) so for a rough calculation (and it is rough)
2200/777 = 2.83 (2.83 what? avi to mpeg2 ratio?)
As for the examples 'top'
2456/720 = 3.41
2252/819 = 2.74
So what can we see here? Well it looks to me that 'maybe' we can come up with a simple furmula for xvid to mpeg2 conversion if it remains true on all avi's....and that would be something like (being conservative here):
To calc xvid/divx to MPEG2 bitrates use a multiplication factor of 3-4X the ORIGINAL avi's bitrate....which is often quoted anyway around the internet anyway...and not a bitrate calculator.
One more thing, FRAMESERVING with AVIsynth to your MPEG encoder does not use the original avi's bitrate at all, its more like a raw compressionless video stream (open up an .avs file with VDub and look at the data rate....132578kbs!!) which I imagine helps the encoder ONE HELL OF A LOT in achieving a good encode.
Originally Posted by monzieThere are 10 kinds of people in this world. Those that understand binary...
OK, just converted the above Equi file with TMPG+ using the same .avs script at 2200kbs..the footage looks good but with a slight loss of detail compared to CCE and a bit 'coarser' looking overall (like some of the detail is not captured correctly...2 pass by the way...maybe low bitrates are not TMPG's best point..but still watchable.....
Note the extra 'noise' on the gun and the less well defined helmet (below)
Its (very) hard to see but there is more noise in this frame than CCE's..look between the strip lights.
All in all I would say TMPG hasnt done a bad job at all....and maybe with a little tweeking in the encoder settings would equal CCE's.
So their you go, a high action sequence (sorry you cant see the full footage) encoded at 2200kbs with TMPG....and just a little 'noise'.
Originally Posted by monzie
EDIT: It's really hard to get a screenshot out of powerdvd =\ if anyone knows a good way to do this, be my guest to enlighten me. btw that 2200 bitrate is very much an average. when i was trying to get my snapshot i noticed that it varied a helluvalot. the biggest i saw (which was splitsecond) was 5.09mbps and the smallest was .82 for a non-black scene and .07 for a full frame of black. My video was a movie w/ a decent amount of action (I, Robot).
There are 10 kinds of people in this world. Those that understand binary...
I wasn't intentionally 'badmouthing' bitrate calculators at all.
If you use a bitrate calc then you will only get a bitrate figure based on the LENGTH of the avi (typically a single movie) and the target DVD size (plus audio etc)......what you DO NOT get is the optimal bitrate. And then theres the 'if the bitrate falls in this range use this res DVD' guides....its simply not true that you have to drop the resolution to get a good encode at low bitrates from xvid/divx sources.
I'm glad you agree with me.
Yes, open the m2v/mpv in VirtualDubMod and then press SHIFT and 1 together and you will then capture a single frame as a .tga..open in a photo-editor and convert to .jpg (50kb max)