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)

GFR 02-28-2003 12:05 PM

Kwag,

Can I make a sticky post to collect some data like Tenra's table? I think with the high activity here I'd be able to have a working file size curve estimator in a month.

kwag 02-28-2003 12:09 PM

Quote:

Originally Posted by GFR
Kwag,

Can I make a sticky post to collect some data like Tenra's table?

Sure you can :D
Quote:

I think with the high activity here I'd be able to have a working file size curve estimator in a month.
Fine, but did you read my posts on the previous page of this thread, regarding average bit rate vs. file size :!: 8)

-kwag

ARnet_tenRA 02-28-2003 12:48 PM

Kwag,

Here is the new prediction function to give you video bitrate:
Code:

#------------------------------#
# Prediction Function          #
#------------------------------#
function Prediction (clip c, string "movie", float "cds", int "cdtime")
{
movie = default(movie,"No_Title_Defined")
cds = default(cds,1)
cdtime = default(cdtime,80)

mSeconds  = framecount(c)/framerate(c)
mFrames  = framecount(c)
CDkBytes = (((cdtime*10)-5)*1024)*cds

a96MB=((( 96*1024)/8)*mSeconds)/1048576
a112MB=(((112*1024)/8)*mSeconds)/1048576
a128MB=(((128*1024)/8)*mSeconds)/1048576
a160MB=(((160*1024)/8)*mSeconds)/1048576
a192MB=(((192*1024)/8)*mSeconds)/1048576
a224MB=(((224*1024)/8)*mSeconds)/1048576

vkbps96=8*(CDkBytes-96*mSeconds/8)/mSeconds
vkbps112=8*(CDkBytes-112*mSeconds/8)/mSeconds
vkbps128=8*(CDkBytes-128*mSeconds/8)/mSeconds
vkbps160=8*(CDkBytes-160*mSeconds/8)/mSeconds
vkbps192=8*(CDkBytes-192*mSeconds/8)/mSeconds
vkbps224=8*(CDkBytes-224*mSeconds/8)/mSeconds

BlankClip(c,1,544,480)
Subtitle(movie, 272,40, halo_color=$5500FF, text_color=$FFFFFF, font="Courier", size=27, align=5)

Subtitle("Total Frames : " + String(mFrames), 80,80)
Subtitle("Time (sec) : " + String(round(mSeconds)), 80,100)

Subtitle("Target average bitrate for " + LeftStr(String(cds),4) + " " + String(cdtime) + "min CD(s):", 80,150, text_color=$FFFFFF)
Subtitle("Audio",150,180,align=5).Subtitle(":",272,180).Subtitle("Video",380,180,align=5)

Subtitle("96 kbps  =",160,210,align=6).Subtitle(String(Round(a96MB)) + "MB",220,210,align=6)
Subtitle(String(Round(vkbps96)) + " kbps  =",385,210,align=6).Subtitle(String(Round(vkbps96*mSeconds/8*1024)) + "MB",450,210,align=6)

Subtitle("112 kbps  =",160,230,align=6).Subtitle(String(Round(a112MB)) + "MB",220,230,align=6)
Subtitle(String(Round(vkbps112)) + " kbps  =",385,230,align=6).Subtitle(String(Round(vkbps112*mSeconds/8*1024)) + "MB",450,230,align=6)

Subtitle("128 kbps  =",160,250,align=6).Subtitle(String(Round(a128MB)) + "MB",220,250,align=6)
Subtitle(String(Round(vkbps128)) + " kbps  =",385,250,align=6).Subtitle(String(Round(vkbps128*mSeconds/8*1024)) + "MB",450,250,align=6)

Subtitle("160 kbps  =",160,270,align=6).Subtitle(String(Round(a160MB)) + "MB",220,270,align=6)
Subtitle(String(Round(vkbps160)) + " kbps  =",385,270,align=6).Subtitle(String(Round(vkbps160*mSeconds/8*1024)) + "MB",450,270,align=6)

Subtitle("192 kbps  =",160,290,align=6).Subtitle(String(Round(a192MB)) + "MB",220,290,align=6)
Subtitle(String(Round(vkbps192)) + " kbps  =",385,290,align=6).Subtitle(String(Round(vkbps192*mSeconds/8*1024)) + "MB",450,290,align=6)

Subtitle("224 kbps  =",160,310,align=6).Subtitle(String(Round(a224MB)) + "MB",220,310,align=6)
Subtitle(String(Round(vkbps224)) + " kbps  =",385,310,align=6).Subtitle(String(Round(vkbps224*mSeconds/8*1024)) + "MB",450,310,align=6)

LanczosResize(width(c), height(c))

return last+c+last
}


GFR 02-28-2003 01:00 PM

I've read it, but I still don't get why average bitrate would be any different from file size, after all average bit rate = file size (in kb) / sample length (in s). That is, file size is in direct proportion with bit rate. My guess is that you were just lucky :). I'm gonna test it anyway.

BTW I always use FitCD/MovieStacker to get my target file size, because it takes in account things like muxing, multiple subtitles, multiple audios, extras, etc.

Anyway if it's discovered that bitrate is more precise for some reason, we can collect bit rate X CQ tables instead.

Yoda 02-28-2003 01:01 PM

@ARnet_tenRA
Would you post how this function would used in a script?

-Yoda

ARnet_tenRA 02-28-2003 01:21 PM

Just place this function at the bottom of your script or in another file and import it.

Then at the bottom of your script , just before SampleClip or Sampler place Prediction()

The first frame of the AVS file is now the output of this function.

Regards, Tenra

ARnet_tenRA 02-28-2003 01:25 PM

Quote:

Originally Posted by GFR
I've read it, but I still don't get why average bitrate would be any different from file size, after all average bit rate = file size (in kb) / sample length (in s). That is, file size is in direct proportion with bit rate. My guess is that you were just lucky :).

This was my point before and it is still true. For prediction, average bitrate and filesize will work equally well. The reason that average bitrate is nice is because you don't have to first determine a target filesize. You just look at the bitrate of your sample (no matter the filesize) and use that for future predictions.

-Tenra

kwag 02-28-2003 01:34 PM

Quote:

Originally Posted by ARnet_tenRA
Kwag,

Here is the new prediction function to give you video bitrate:

What can I say, BEAUTIFUL :mrgreen:

-kwag

rendalunit 02-28-2003 01:39 PM

What is the desired avg. bitrate :?:

Here's three samples of Heist
Code:

cq    size (mb)      avg. bitrate
--    -----------    -------------
100        26.281        1767
50        8.889        597
0          6.286        422

The problem i see with determining the cq from the bitrate is that it's not proportional to it. However the bitrate is directly proportional to the filesize but that doesn't help to find the cq value 8O .

ren

kwag 02-28-2003 01:45 PM

Quote:

Originally Posted by rendalunit
What is the desired avg. bitrate :?:

Here's three samples of Heist
Code:

cq    size (mb)      avg. bitrate
--    -----------    -------------
100        26.281        1767
50        8.889        597
0          6.286        422

The problem i see with determining the cq from the bitrate is that it's not proportional to it. However the bitrate is directly proportional to the filesize but that doesn't help to find the cq value 8O .

ren

Hi ren,

Open your .d2v with MovieStacker, and look at the suggested average bit rate. Say it is 890Kbps. With your numbers above, you would take the average produced with CQ=100. So 890/1767=50.36 So 50.36 would be the suggested CQ value ( kinda low for one CD :? )
But you don't need to run a full sampler. Just ~30% should do.

-kwag

-kwag

kwag 02-28-2003 01:55 PM

@Tenra,
Just ran an average bit rate sample on the movie "xXx" using your script. Bingo :!: target again on the first run :lol:

-kwag

labomba 02-28-2003 02:05 PM

@Kwag

On MovieStacker the GOP options is set to 15, Need I change to 24, or that's not important?
Also, the avg bitrate for The Last Castle for me was 1015, is that correct? Could you give me the settings (resolution, cq, 1 or 2 cds) of The Last Castle?
Thanks!
LaBomba

rendalunit 02-28-2003 02:06 PM

hey kwag,

MovieStacker gave a recommended avg bitrate of 841. So 841/1767=.47 or cq=47 <- This is way off! I've already encoded a full sample of Heist with every whole cq value and the one that came closest to the desired filesize of 11.54mb with 128kbps audio was cq=62 8O

ren

kwag 02-28-2003 02:10 PM

Quote:

Originally Posted by rendalunit
hey kwag,

MovieStacker gave a recommended avg bitrate of 841. So 841/1767=.47 or cq=47 <- This is way off! I've already encoded a full sample of Heist with every whole cq value and the one that came closest to the desired filesize of 11.54mb with 128kbps audio was cq=62 8O

ren

8O Are you using the same script you used for CQ=62 :?:, or have you made any changes :?:
Can you run your sampler again with a CQ of 47 to see what is the actual file size :?:

-kwag

rendalunit 02-28-2003 02:19 PM

The sample with cq-47 was 8.906 I used the same script with all the samples.

ren

kwag 02-28-2003 02:30 PM

@Tenra,

I think that what we need is your "Scale" factor table, but instead of the center being 50, it has to be CQ=100 equals the factor of 1.0
So then we encode the sampler at CQ=100 and take the average bit rate, then we adjust with the scale factor. This would still only require one sampler run.

@Ren,
The above should then work for the non-linearity conditions.

The scale would be something like this:

Code:

CQ 100: Factor 1.0
CQ  99: Factor .9x
CQ  98: Factor .9x etc, etc

Now, i'm on to make a scale 8)

Edit: See you all in about a couple of hours, because I'm doing a CQ spreadsheet from 100 down to 1 in steps of one, and each sample is ~1 minute 8O :lol:
I'll post the result when done.


-kwag

ARnet_tenRA 02-28-2003 02:49 PM

Quote:

Originally Posted by rendalunit
Code:

cq    size (mb)      avg. bitrate
--    -----------    -------------
100        26.281        1767
50        8.889        597
0          6.286        422


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.

-Tenra

alfredini 02-28-2003 02:53 PM

@Tenra.
Everytime i use your SampleClip() (or SampleClip(n)) the TMPGEnc shows me the number of frames of the complete movie. Although it codes not the complete movie it needs is to much time. Also the file is huge.
Whats wrong?

kwag 02-28-2003 02:56 PM

I just wish CQ would be a linear scale :cry:
Then we wouldn't have all this trouble :x

-kwag

ARnet_tenRA 02-28-2003 03:06 PM

Quote:

Originally Posted by alfredini
@Tenra.
Everytime i use your SampleClip() (or SampleClip(n)) the TMPGEnc shows me the number of frames of the complete movie. Although it codes not the complete movie it needs is to much time. Also the file is huge.
Whats wrong?

First, make sure that on the audio input line you remove the avs script. (Only have something listed on the video line and the output line.

Second, make sure that you have the newest version from my sig below, I tend to make updates often. If you have the newest version you can disregard the first suggestion since I have fixed it.

-Tenra


All times are GMT -5. The time now is 10:18 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.