digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   A new way to calculate CQ... maybe? (http://www.digitalfaq.com/archives/avisynth/2340-calculate-cq.html)

alfredini 02-28-2003 03:21 PM

Of course... the audio... :x
i am usualy not using AviSource(movie, FALSE).
Anyway thanks a lot :D

rendalunit 02-28-2003 04:38 PM

Quote:

Originally Posted by kwag
I just wish CQ would be a linear scale icon_cry.gif
Then we wouldn't have all this trouble

Yeah, but what fun would that be? :mrgreen:

Ok I finally finished my spreadsheet- lot of work for file prediction :!:

I encode samples of Heist with this script:
Code:

Mpeg2Source("D:\HEIST\VIDEO_TS\heist.d2v")
LegalClip()
BilinearResize(512,344,3,0,714,480)
AddBorders(8,68,8,68)
LegalClip()

which is very basic- no noise filters

here's the result:
http://www.digitalfaq.com/archives/error.gif
here's the excel file for the Sigmoidal Curve parameter sticky post 8O: Heist_data.xls

I still think it may be possible to create a linear equation based on cq0 to ~cq50 and combine another one for cq50 to ~cq80 8O

ren

rendalunit 02-28-2003 05:58 PM

Quote:

Originally Posted by ARnet_tenRA
The problem I see with these values is that your CQ100 seem way out of proportion with the CQ0 and CQ50 values.

Using the scale I had posted before you should only have about 17.778MB and 1194 as the avg. bitrate for CQ100. ie: double CQ50

Your CQ100 is triple CQ50 and that is why the formula is not working.

Yep, that is very weird 8O I wonder if this might have to do with the resolution :?: I used the KVCDx3 528x480 template
http://www.digitalfaq.com/archives/error.gif

ARnet_tenRA 02-28-2003 09:11 PM

Quote:

Originally Posted by rendalunit
I wonder if this might have to do with the resolution :?: I used the KVCDx3 528x480 template

That is a very good possibility. I used 352x240 for my tests.

-Tenra

kwag 02-28-2003 09:14 PM

If this means that the curves are different for each resolution, we're screwed 8O

ARnet_tenRA 02-28-2003 09:23 PM

Quote:

Originally Posted by kwag
If this means that the curves are different for each resolution, we're screwed 8O

Don't worry, I'm working on a new formula where you take 3 or 4 short samples and the curve for your movie is automatically determined. :wink:

-Tenra

rendalunit 02-28-2003 11:55 PM

I encoded a bunch of samples of"the Matrix" at 528x480 and graphed the sizes and it follows exactly the same pattern!
http://www.digitalfaq.com/archives/error.gif
The peak file sizes (or the "ceiling") is higher with the Matrix samples 8O The bottom line is that it may be possible to determine the final size of the encode with one short sample at cq-100 and with a good formula (maybe range adjusted by resolution or number of pixels), making the process simpler :D :tongue2:

ren

kwag 02-28-2003 11:59 PM

OK, I'm finally done, and I think I have good news :!:

First, a chart, and then the explanation :lol: :

Code:

CQ        FS          ABR        !ABR          *CQ

100  4349        1603        1603          100
99        4336        1598        1586.97        98.32
98        4323        1593        1570.94        96.64
97        4310        1589        1554.91        94.92
96        4298        1584        1538.88        93.27
95        4287        1580        1522.85        91.56
94        4276        1576        1506.82        89.87
93        4265        1572        1490.79        88.2
92        4255        1568        1474.76        86.53
91        4246        1565        1458.73        84.82
90        4237        1561        1442.7        83.18
89        4228        1558        1426.67        81.5
88        4219        1555        1410.64        79.83
87        4211        1552        1394.61        78.18
86        4204        1549        1378.58        76.54
85        4196        1546        1362.55        74.91
84        4171        1537        1346.52        73.59
83        4032        1486        1330.49        74.31
82        3884        1431        1314.46        75.32
81        3692        1361        1298.43        77.28
80        3419        1259        1282.4        81.49
79        3085        1136        1266.37        88.07
78        2990        1101        1250.34        88.58
77        2985        1099        1234.31        86.48
76        2980        1097        1218.28        84.4
75        2975        1095        1202.25        82.35
74        2966        1092        1186.22        80.38
73        2880        1060        1170.19        80.59
72        2784        1025        1154.16        81.07
71        2613        961        1138.13        84.09
70        2402        884        1122.1        88.85
69        2362        869        1106.07        87.82
68        2361        869        1090.04        85.3
67        2356        867        1074.01        83
66        2352        866        1057.98        80.63
65        2298        845        1041.95        80.15
64        2222        817        1025.92  80.37
63        2078        765        1009.89        83.17
62        1987        731        993.86        84.29
61        1985        731        977.83        81.6
60        1983        730        961.8          79.05
59        1978        728        945.77        76.65
58        1947        717        929.74        75.21
57        1882        693        913.71        75.15
56        1773        653        897.68        76.98
55        1768        651        881.65        74.49
54        1759        647        865.62        72.25
53        1756        647        849.59        69.6
52        1742        641        833.56        67.62
51        1695        624        817.53        66.82
50        1623        597        801.5          67.13
49        1615        595        785.47        64.69
48        1613        594        769.44        62.18
47        1616        595        753.41        59.51
46        1602        590        737.38        57.49
45        1546        569        721.35        57.05

Please ignore the three columns in the center. They were used only for reference while creating the factors. The important numbers are the CQ on the left, and the *CQ on the right ONLY.

FS=File Size.
ABR=Average Bit Rate.
!AVBR=Linear(should be) Average Bit Rate.
*CQ=Use this CQ to encode.

This was done with 352x480 template to pick a "half way" point for resolution.

Now you only need to run a sampler ( ~30% or full ) one time only with CQ=100 :!:

And do this:
(1)Lookup the average bit rate that MovieStacker suggested.
(2)Divide Moviestacker's suggested average bit rate by your real average bit rate of your sample as seen on BitRate Viewer, and multiply by 100.
(3)Look up the closest number you got in step (2) IN THE LEFT CQ values column of the chart, and use the *CQ on the same line on the far right

Tada!. That's it.

Please let me know if this is on target, or if it has been a waste of time :cry:

Edit: Suggestion, I think it's better to run the one time full sampler instead of ~30%. This way we get a more accurate bit rate for the prediction. Also these numbers are to be used with KVCD's Q Matrix and GOP. They will be WAY off with anything else :!:

-kwag

kwag 03-01-2003 12:00 AM

@Ren,

Take a look at the numbers and see if it now matches close to what you had encoded before :wink:

-kwag

muaddib 03-01-2003 01:48 AM

Hey! 8O
If this works I can code this chart into MovieStacker and
make a Prediction Tab to make all the choices and calculations! :wink:

kwag 03-01-2003 02:11 AM

Quote:

Originally Posted by muaddib
Hey! 8O
If this works I can code this chart into MovieStacker and
make a Prediction Tab to make all the choices and calculations! :wink:

Yesssssssssss :mrgreen:

I need people to test this. The chart was based on a 20 second sample. If the prediction is not at least 98% accurate, then I'll do a batch job overnight with a longer sampler, and then feed in the new values to the spreadsheet.

-kwag

Smoochie3 03-01-2003 02:20 AM

Ok, my movie was Ronin.
MovieStacker says average bitrate was 2064 kbps.
Bitrate viewer says 1495
2064/1495 = 1.380602007 x 100 = 138.0602007 ?!?!?!

I used 528x480 with this script:
Code:

Import ("G:\sample avisynth scripts\LoadPlugins.h")

Mpeg2Source("G:\video_ts\Ronin.d2v")

LegalClip()
Telecide()
Decimate()
Gripcrop(528,480)
Gripsize(resizer="lanczosresize")
mergechroma(blur(1.58))
mergeluma(blur(0.2))
SpaceDust()
FluxSmooth(7,7)
NoMoSmooth(40,1,6,1,3,false)
Convolution3d(preset="movieHQ")
DctFilter(1,1,1,1,1,1,.5,0)
GripBorders()
LetterBox(0, 0, 8, 8)
LegalClip()

Sampler(length=24)

What did i do wrong?

kwag 03-01-2003 02:25 AM

Quote:

Originally Posted by Smoochie3

What did i do wrong?

2064 kbps average, 8O, no way :!:
Look again at the LEFT value on MovieStacker.
Right under the "Minutes" field.

-kwag

Smoochie3 03-01-2003 02:28 AM

LOL! :imstupid: i figured it out, thanks!

Ok, so....

Ok, my movie was Ronin.
MovieStacker says average bitrate was 1001 kbps.
Bitrate viewer says 1495
1001/1495 = .6695652174 x 100 = 66.95652174.

So, i would use a CQ of 83?

kwag 03-01-2003 02:53 AM

Quote:

Originally Posted by Smoochie3
LOL! :imstupid: i figured it out, thanks!

Ok, so....

Ok, my movie was Ronin.
MovieStacker says average bitrate was 1001 kbps.
Bitrate viewer says 1495
1001/1495 = .6695652174 x 100 = 66.95652174.

So, i would use a CQ of 83?

That's it :)
Tell me your results :wink:

-kwag

PyRoMaNiA 03-01-2003 12:22 PM

8O Wow. A lot has happened since I was last here......

It might be just me but when I ran a full sampler, got the correct CQ, and then used this CQ and ran another sampler using manual file size prediction, the resulting file was about 2 megs bigger than my target size... :(

kwag 03-01-2003 12:28 PM

Quote:

Originally Posted by PyRoMaNiA
8O Wow. A lot has happened since I was last here......

It might be just me but when I ran a full sampler, got the correct CQ, and then used this CQ and ran another sampler using manual file size prediction, the resulting file was about 2 megs bigger than my target size... :(

WARNING -SLIPPERY WHEN WET :lol: ALPHA ALPHA ALPHA Method, not even BETA

That's related to ALL my posts in this thread.
Ok, so you mean your "sampler" file size was ~2MB larger than with the standard method of file prediction :?:
What was your resolution :?:

-kwag

rendalunit 03-01-2003 12:43 PM

hey kwag,

I tried the table and it worked great 1/2 times- first time very close- second time off pretty badly :? If you want you can download my excel worksheet of Heist that I posted-- did you see that?

I'm confused about a couple things though:

1. The curve range is totally different between 352x240 and 528x480 (assuming the resolution is causing this)- so won't the error factor be different?

2. Why not just use filesize and not bitrate? Using the bitrate is a serious pain- first the recommended bitrate to use in MovieStacker is based on all the settings on the page (most relate to SVCD) :roll: It would be so much easier to just enter your error factor into the Predict2 function and it will display the correct cq to use :idea:

thanks,
ren

PyRoMaNiA 03-01-2003 12:44 PM

Quote:

Ok, so you mean your "sampler" file size was ~2MB larger than with the standard method of file prediction :?:
That's right, and my resolution was 352x480.

kwag 03-01-2003 12:50 PM

Quote:

Originally Posted by rendalunit
hey kwag,

I tried the table and it worked great 1/2 times- first time very close- second time off pretty badly :? If you want you can download my excel worksheet of Heist that I posted-- did you see that?

I'm confused about a couple things though:

1. The curve range is totally different between 352x240 and 528x480 (assuming the resolution is causing this)- so won't the error factor be different?

2. Why not just use filesize and not bitrate? Using the bitrate is a serious pain- first the recommended bitrate to use in MovieStacker is based on all the settings on the page (most relate to SVCD) :roll: It would be so much easier to just enter your error factor into the Predict2 function and it will display the correct cq to use :idea:

thanks,
ren

Hi ren,

Yes, the resolutions throw off the curve completely 8O.
I guess this exercise did turn into a "crap" ( for my posts :cry: ), because the method is very tightly integrated with the MIN, MAX and resolution I used. So there would have to be a chart for every template, and then if anything is changed ( matrix, etc. ) that would mean that a whole new chart would be needed. So, I slipped and fell on this one :twisted:
Thanks for trying it out. Now I'll go dig a hole in the ground and proceed to insert myself in it for a couple of hours, and meditate :roll: :x :x

-kwag

kwag 03-01-2003 12:51 PM

Quote:

Originally Posted by PyRoMaNiA
Quote:

Ok, so you mean your "sampler" file size was ~2MB larger than with the standard method of file prediction :?:
That's right, and my resolution was 352x480.

:x Read my response to ren above :x

PyRoMaNiA 03-01-2003 12:53 PM

Quote:

Quote:
Ok, so you mean your "sampler" file size was ~2MB larger than with the standard method of file prediction icon_question.gif


That's right, and my resolution was 352x480.
No, wait, thats not what I mean :? ...I meant I ran Sampler at CQ 100, divided Moviestacker average by BitrateCalc average, turned out at 88.85...I then encoded a sample at 88.85, and, according to manual filesize prediction, my file should have been 11.4 MBs, actual file was 13.5.

PyRoMaNiA 03-01-2003 12:55 PM

Oops, didn't see your post kwag......oh dear.... :cry:

kwag 03-01-2003 01:00 PM

Quote:

Originally Posted by PyRoMaNiA

No, wait, thats not what I mean :? ...I meant I ran Sampler at CQ 100, divided Moviestacker average by BitrateCalc average, turned out at 88.85...I then encoded a sample at 88.85, and, according to manual filesize prediction, my file should have been 11.4 MBs, actual file was 13.5.

Right, that's what I thought. That's exactly the difference I got.
Now wait a minute :!: , coincidence :?: or could this mean we have a constant factor :idea: 11.4/13.5 = 0.84 so 0.84 * (*CQ) in chart for 352x480 resolution :idea: ( Last try :!: )
If that is the case, there is just one constant for different resolutions, and the same chart :idea:
Let me know, so I don't finish digging the hole 8)

-kwag

Smoochie3 03-01-2003 01:06 PM

Does it make any difference if your target is 1 CD or 2 CD's for this chart? My sample size for Ronin is 21.5 Mb, which might be ok for 2 CD's, but what if i want it on 1 CD? I'm using KVCDx3.

rendalunit 03-01-2003 01:12 PM

hey kwag,

don't feel bad- I can't tell you how long i worked on that cheesy file size predictor thingy and then SansGrip put a nice one out with a gui at the same time (that was funny) :oops: :lol:

The good news is the shape of the curve is the same (i think more testing should be done to confirm this) so maybe if one sample at cq100 is encoded then the range of the curve can be adjusted in the equation based on the resolution :idea:

ren

kwag 03-01-2003 01:19 PM

Quote:

Originally Posted by rendalunit
hey kwag,

don't feel bad- I can't tell you how long i worked on that cheesy file size predictor thingy and then SansGrip put a nice one out with a gui at the same time (that was funny) :oops: :lol:

:mrgreen:
Quote:

The good news is the shape of the curve is the same (i think more testing should be done to confirm this) so maybe if one sample at cq100 is encoded then the range of the curve can be adjusted in the equation based on the resolution :idea:

ren
I just got a diff of .83 (see my previous post ) on another sampler, also at 352x480 8O.
So I'm running a sampler with the chart value * .83 to see if it hits the same file size that the regular formula wants. Then I'll try another movie to see if the factor is constant on a resolution basis.

-kwag

vhelp 03-02-2003 01:22 AM

Hi Kwag..

I was following along Friday at work, and now here at home, (since I've
ben away surfing other areas of the world on a project)

Don't give up too easy. How about just mapping out for each of the major
resolutions and then formulating a Function(res, CDs, CQ) = CQ ??

The data could be stored in a table or DB table and imported into the final
App upon startup. This way, when NEWer data (continues, as it will) flowing
in, those will simply be added in to the calculation factor. Follow me so
far ??

Well, I have some reading up to do, as well as learn a few new things..

-vhelp

PyRoMaNiA 03-04-2003 01:11 PM

Well, it looks like the resolution doesn't really affect the curve to me...but then I could be wrong...anyway I made this to try and make some use of the data we have so far:
CQestimation.xls

I just used kwags results, and divided each filesize by the CQ 100 filesize to get a factor for each one, with CQ 100 as 1.000.

It seems to be able to predict an approximate CQ quite well on only a third sampler...although it sometimes underestimates the CQ quite a bit, but hasn't overestimated it yet, but then I haven't really tested it properly.

In only works in whole CQ numbers which probably affects how accurate it can be...looks to me like it needs a lot of work to be more accurate. Well, let me know if :imstupid: ......

PyRoMaNiA 03-07-2003 01:07 PM

It's a really stupid idea??? :oops:

Or has this project been abandoned and I just haven't realised yet?

rendalunit 03-07-2003 01:27 PM

Hey Pyromania,

I was not able to download your worksheet before, I got an error screen from geocities but I tried it again and now I'm looking at it in Excel 8)

I'm not giving up on this yet :roll: I've been doing tons of sample encodes and it's very time consuming :wink:

I'm going to check out your worksheet now

Here's the one I've been working on prediction.xls

ren


All times are GMT -5. The time now is 11:47 PM  —  vBulletin © Jelsoft Enterprises Ltd

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.