A New Way to Calculate CQ... Maybe? - Page 2 - digitalFAQ.com Forums [Archives]
 digitalFAQ.com Forums [Archives] a New Way to Calculate CQ... Maybe?

#21
02-28-2003, 12:05 PM
 GFR Free Member Join Date: May 2002 Posts: 438 Thanks: 0 Thanked 0 Times in 0 Posts
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.
Someday, 12:01 PM
 Site Staff / Ad Manager Join Date: Dec 2002 Posts: 42 Thanks: ∞ Thanked 42 Times in 42 Posts
#22
02-28-2003, 12:09 PM
 kwag Free Member Join Date: Apr 2002 Location: Puerto Rico, USA Posts: 13,537 Thanks: 0 Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by GFR Kwag, Can I make a sticky post to collect some data like Tenra's table?
Sure you can
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

-kwag
#23
02-28-2003, 12:48 PM
 ARnet_tenRA Free Member Join Date: Jan 2003 Location: Illinois, USA Posts: 73 Thanks: 0 Thanked 0 Times in 0 Posts
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
}```
#24
02-28-2003, 01:00 PM
 GFR Free Member Join Date: May 2002 Posts: 438 Thanks: 0 Thanked 0 Times in 0 Posts
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.
#25
02-28-2003, 01:01 PM
 Yoda Free Member Join Date: Apr 2002 Posts: 172 Thanks: 0 Thanked 0 Times in 0 Posts
@ARnet_tenRA
Would you post how this function would used in a script?

-Yoda
__________________
May the code force be with you
#26
02-28-2003, 01:21 PM
 ARnet_tenRA Free Member Join Date: Jan 2003 Location: Illinois, USA Posts: 73 Thanks: 0 Thanked 0 Times in 0 Posts
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
#27
02-28-2003, 01:25 PM
 ARnet_tenRA Free Member Join Date: Jan 2003 Location: Illinois, USA Posts: 73 Thanks: 0 Thanked 0 Times in 0 Posts
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
#28
02-28-2003, 01:34 PM
 kwag Free Member Join Date: Apr 2002 Location: Puerto Rico, USA Posts: 13,537 Thanks: 0 Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by ARnet_tenRA Kwag, Here is the new prediction function to give you video bitrate:
What can I say, BEAUTIFUL

-kwag
#29
02-28-2003, 01:39 PM
 rendalunit Free Member Join Date: Apr 2002 Location: san jose, Ca Posts: 1,148 Thanks: 0 Thanked 0 Times in 0 Posts
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 .

ren
#30
02-28-2003, 01:45 PM
 kwag Free Member Join Date: Apr 2002 Location: Puerto Rico, USA Posts: 13,537 Thanks: 0 Thanked 0 Times in 0 Posts
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 . 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
#31
02-28-2003, 01:55 PM
 kwag Free Member Join Date: Apr 2002 Location: Puerto Rico, USA Posts: 13,537 Thanks: 0 Thanked 0 Times in 0 Posts
@Tenra,
Just ran an average bit rate sample on the movie "xXx" using your script. Bingo target again on the first run

-kwag
#32
02-28-2003, 02:05 PM
 labomba Free Member Join Date: Jan 2003 Location: S.Paulo-Brasil Posts: 185 Thanks: 0 Thanked 0 Times in 0 Posts
@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
#33
02-28-2003, 02:06 PM
 rendalunit Free Member Join Date: Apr 2002 Location: san jose, Ca Posts: 1,148 Thanks: 0 Thanked 0 Times in 0 Posts
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

ren
#34
02-28-2003, 02:10 PM
 kwag Free Member Join Date: Apr 2002 Location: Puerto Rico, USA Posts: 13,537 Thanks: 0 Thanked 0 Times in 0 Posts
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 ren
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
#35
02-28-2003, 02:19 PM
 rendalunit Free Member Join Date: Apr 2002 Location: san jose, Ca Posts: 1,148 Thanks: 0 Thanked 0 Times in 0 Posts
The sample with cq-47 was 8.906 I used the same script with all the samples.

ren
#36
02-28-2003, 02:30 PM
 kwag Free Member Join Date: Apr 2002 Location: Puerto Rico, USA Posts: 13,537 Thanks: 0 Thanked 0 Times in 0 Posts
@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

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
I'll post the result when done.

-kwag
#37
02-28-2003, 02:49 PM
 ARnet_tenRA Free Member Join Date: Jan 2003 Location: Illinois, USA Posts: 73 Thanks: 0 Thanked 0 Times in 0 Posts
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
#38
02-28-2003, 02:53 PM
 alfredini Free Member Join Date: Dec 2002 Posts: 38 Thanks: 0 Thanked 0 Times in 0 Posts
@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?
#39
02-28-2003, 02:56 PM
 kwag Free Member Join Date: Apr 2002 Location: Puerto Rico, USA Posts: 13,537 Thanks: 0 Thanked 0 Times in 0 Posts
I just wish CQ would be a linear scale
Then we wouldn't have all this trouble

-kwag
#40
02-28-2003, 03:06 PM
 ARnet_tenRA Free Member Join Date: Jan 2003 Location: Illinois, USA Posts: 73 Thanks: 0 Thanked 0 Times in 0 Posts
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

 Similar Threads Thread Thread Starter Forum Replies Last Post pappukanghi Video Encoding and Conversion 8 10-13-2004 11:47 AM Prodater64 Video Encoding and Conversion 3 08-25-2004 03:55 AM azel Video Encoding and Conversion 3 07-22-2003 06:15 PM black prince Video Encoding and Conversion 5 12-08-2002 12:19 AM marky Video Encoding and Conversion 2 06-16-2002 05:10 PM