Quantcast Still Having Problems with CQ Prediction - digitalFAQ.com Forums [Archives]
  #1  
03-30-2004, 12:44 PM
p2phunter p2phunter is offline
Free Member
 
Join Date: Mar 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
I've been into KVCDs for quite some time now. (Actually.. its nothing when compared to many other ppl in these forums )

But one thing which has still evaded me is the CQ prediction. I've tried ToK, ACP, CQMatic and the Manual Prediction from here. But nothing has given me correct CQ.

Most of the time my final MPG file will be smaller than expected. Like yesterday, I converted one of my XVID files to KVCD. I used CQMatic to predict the CQ. And when I used the CQ predicted by CQMatic, I got a mpg file which was of size ~ 700MB(after multiplexing with Audio). This is like 100MBs shorter than the desired size. Later, I got to know that CQMatic isnt accurate when it comes to AVI files. Still, when I burn it on a CD as KVCD and play it on my standalone player, both the audio and video quality was pretty good. But I guess it would have better if the size of the MPG was around 800MB.

Later, I tried to predict the CQ required for some other XVID file that I had using the manual prediction method given here. The AVS script that I used is given below.

Code:
## DLL Section ## 
# 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\MPEG2Dec3.dll") 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\GripFit_YV12.dll") 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\STMedianFilter.dll") 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\asharp.dll") 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\UnFilter.dll") 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\UnDot.dll")

#You might need to change this
Import("D:\KVCD\AviSynth\AviSynth 2.5\Functions\functions.avs") 

#Variables to be set
SampleSize=0
CQ=0
movie="Sample Movie"  
cds=1 
cdtime=80 
MinAudioBitrate=112 
factor=0.98 


# 
#### 
## Main section and static filters ### 
# 
AviSource("Q:\Sample Movie.avi",false)
# 
undot() 
Limiter() 
asharp(1, 4) 
GripCrop(352, 240, overscan=2, source_anamorphic=false)
GripSize(resizer="BicubicResize") 
STMedianFilter(3, 3, 1, 1 ) 
MergeChroma(blur(1.5)) 
MergeLuma(blur(0.1))
# 
# 


## Linear Motion Adaptive Filtering ## 
# 
# ( Portions from AviSynth's manual ) 
# This will apply variable temporalsoften 
# and variable blur. 
# Both filters are active at all times, and work inversely proportional to the 
# activity, measured from current frame to next frame. 

ScriptClip(" nf = YDifferenceToNext()" +chr(13)+ "unfilter( -(fmin(round(nf)*2, 100)), -(fmin(round(nf)*2, 100)) ).TemporalSoften( fmin( round(2/nf), 6), round(1/nf) , round(3/nf) , 1, 1)  ") 

# 
# 
# 

GripBorders() 
#LetterBox( Your_Values_Here ) # Depends on situation. Use MovieStacker! 
Limiter() 


prediction(movie, cds , cdtime, factor, SampleSize, CQ, MinAudioBitrate). Sampler(length=24)
# 
# 
## Functions ### 

function fmin( int f1, int f2) { 
  return ( f1<f2 ) ? f1 : f2 
} 
  
# 
####

The file functions.avs is given below

Code:
#------------------------------# 
# Prediction Function # 
#------------------------------# 

function Prediction (clip c, string "movie", int "cds", int "cdtime", float "factor", float "SampleSize", float "CQ", int "MinAudioBitrate") 

{ 
movie = default(movie,"No_Title_Defined") 
factor = default(factor,0.98) 
cds = default(cds,0) 
cdtime = default(cdtime,80) 
SampleSize = default(SampleSize,0) 
CQ = default(CQ,0) 
MinAudioBitrate = default(MinAudioBitrate,128) # lowest audio bitrate wanted 

MovieLength = framecount(c)/framerate(c) 
FramesTotal = framecount(c) 
FramesSample = framecount(Sampler(c,length=24)) 
CD_Size = (((cdtime*10)-5)*1024)*cds 

MinAudio = (((((CD_Size-((MinAudioBitrate/8)*Movielength))*FramesSample)/FramesTotal)*factor))/1000 
EncodedSample = (SampleSize==0)? false: true #-------------------------------------------------------------------- 
SampleSize = (SampleSize==0)? 1: SampleSize # if sample size =0 mb then no previous sample. 
CQ = (CQ<=0)? 1 :CQ # set cq between 1-100 
CQ = (CQ>100)?100 : CQ #--------------------------------------------------------------------- 
SampleSizeMessage=(EncodedSample==false)?"no sample encoded yet **********": "Sample Size (mb) : " 
SampleCQMessage=(EncodedSample==false)?"no sample encoded yet **********":"Sample CQ : " 
TryCQValueMessage=(EncodedSample==false)?"no sample encoded yet ******":"Try CQ value of : " 

d=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(FramesTotal), 80,60). 
\Subtitle("Sample Frames : " + String(FramesSample), 80,80). 
\Subtitle("Time (sec) : " + String(round(Movielength)), 80,100). 
\Subtitle("Time (min) : " + String(round(Movielength/60)), 80,120). 

\Subtitle(SampleSizeMessage+LeftStr(String(SampleSize),5), 270,60,text_color=$FF0000). 
\Subtitle(SampleCQMessage + LeftStr(String(CQ),4),270,80,text_color=$FF0000). 
\Subtitle("Min. Audio Bitrate : "+ String(MinAudioBitrate)+" kbps",270,100,text_color=$FF0000). 
\Subtitle("Desired Sample Size (mb) : " + LeftStr(String(MinAudio),5),270,120,text_color=$FF0000). 
\Subtitle(TryCQValueMessage + LeftStr(String((MinAudio*CQ)/SampleSize),4),270,140,text_color=$FF0000). 

\Subtitle("Desired Sample Size (mb) for " + String(cds) + " CD(s):", 80,165, text_color=$FFFFFF). 
\Subtitle("- audio at 96 kbps : " + LeftStr(String((((((CD_Size-((096/8)*Movielength))*FramesSample)/FramesTotal)*factor))/1000),5),80,185). 
\Subtitle("- audio at 112 kbps : " + LeftStr(String((((((CD_Size-((112/8)*Movielength))*FramesSample)/FramesTotal)*factor))/1000),5),80,205). 
\Subtitle("- audio at 128 kbps : " + LeftStr(String((((((CD_Size-((128/8)*Movielength))*FramesSample)/FramesTotal)*factor))/1000),5),80,225). 
\Subtitle("- audio at 160 kbps : " + LeftStr(String((((((CD_Size-((160/8)*Movielength))*FramesSample)/FramesTotal)*factor))/1000),5),80,245). 
\Subtitle("- audio at 192 kbps : " + LeftStr(String((((((CD_Size-((192/8)*Movielength))*FramesSample)/FramesTotal)*factor))/1000),5),80,265). 
\Subtitle("- audio at 224 kbps : " + LeftStr(String((((((CD_Size-((224/8)*Movielength))*FramesSample)/FramesTotal)*factor))/1000),5),80,285). 

\Subtitle("Average Bitrate (kbps) : "+ String(Round(((((CD_Size-((128/8)*Movielength)))/Movielength)*8)*1)), 80,328). 

\Subtitle("Predicted Audio File Sizes (mb):", 80,373, text_color=$FFFFFF). 
\Subtitle(" 96 kbps = " + String(Round(((( 96*1024)/8)*Movielength)/1048576)),80,395). 
\Subtitle("112 kbps = " + String(Round((((112*1024)/8)*Movielength)/1048576)),80,416). 
\Subtitle("128 kbps = " + String(Round((((128*1024)/8)*Movielength)/1048576)),80,437). 
\Subtitle("160 kbps = " + String(Round((((160*1024)/8)*Movielength)/1048576)),270,395). 
\Subtitle("192 kbps = " + String(Round((((192*1024)/8)*Movielength)/1048576)),270,416). 
\Subtitle("224 kbps = " + String(Round((((224*1024)/8)*Movielength)/1048576)),270,437). 

\BilinearResize(width(c), height(c)) 
return d+c+d 
}
I was able to view the avs file in WMP. Now, the first time, I set the variables SampleSize and CQ to 0 when I called the function prediction. And once encoding is done, I got the file size and CQ and substituted them to the old values. The suggested CQ (displayed as a subtitle on the first screen) was 90. I did it again and now the suggested CQ was 68. Then it started to oscillate between ~69 and ~91. The required sample size was 11.6Megs. But with CQ of 68, the sample size size was ~8Megs and with CQ of 91, the sample size was ~13-14Megs.

(Edit: When I encoded with TMPGenc, I had set the stream type as Video Only. Does it make any difference?)

So, I stopped using the suggested CQ (that was displayed as a subtitle on the screen) and made my own trial and error encodings with different CQs until I got a file size ~ equal to the required sample size. And, I used this CQ to encode my movie. I got a nice MPEG file of size 787MB.

But, the formula that kwag has suggested didnt work. What could be the reason. Could it be because the source was AVI?. What am I doing wrong.
__________________
-p2p hvnt3r-
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Site Staff / Ad Manager
 
Join Date: Dec 2002
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
  #2  
03-30-2004, 01:18 PM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
I really don't know where you find this script (and I apologize to the author) but there are more things to change or remove in it than lines to keep (I mean, if you are encoding an xvid) ! So just forget it.

What was the script you used when you tried CQMatic and other tools ?
Reply With Quote
  #3  
03-30-2004, 06:28 PM
jorel jorel is offline
Invalid Email / Banned / Spammer
 
Join Date: Aug 2002
Location: Brasil - MG - third stone from the sun
Posts: 5,570
Thanks: 0
Thanked 0 Times in 0 Posts
(and I apologize to the author).....

Reply With Quote
  #4  
03-30-2004, 07:10 PM
p2phunter p2phunter is offline
Free Member
 
Join Date: Mar 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Actually, I got the script from here
http://www.kvcd.net/forum/viewtopic.php?t=3483

I got the prediction part of the script from here
http://www.kvcd.net/forum/viewtopic.php?t=2102

And.. I used the same script when predicting using CQMatic which I guess isnt right

But... now I notice that the script was for DVD source. So I guess, I must use some other script for AVIs. Can some one point me to a good and optimal AVS script for AVI source?

thanks for your help!
__________________
-p2p hvnt3r-
Reply With Quote
  #5  
03-30-2004, 07:29 PM
Prodater64 Prodater64 is offline
Free Member
 
Join Date: Mar 2003
Location: Palma de Mallorca - España
Posts: 2,925
Thanks: 0
Thanked 0 Times in 0 Posts
Please, read ALL in this thread. Is very usefull
http://www.kvcd.net/forum/viewtopic....626&highlight=
Reply With Quote
  #6  
03-30-2004, 07:31 PM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
Trust me, I didn't say all this just because I provided the optimal scripts for avi

You'll find them here :
http://www.kvcd.net/forum/viewtopic.php?t=7223
Reply With Quote
  #7  
03-30-2004, 07:48 PM
p2phunter p2phunter is offline
Free Member
 
Join Date: Mar 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
thanks pal

Thanks to you too prodater!
__________________
-p2p hvnt3r-
Reply With Quote
  #8  
03-31-2004, 12:38 PM
p2phunter p2phunter is offline
Free Member
 
Join Date: Mar 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
I got ur (DialHot's) optimal script for AVI's and used it to convert one of my AVI's to KVCD. This is the script (v4) I used

(the width and height of the movie were divisible by 16)

Code:
## DLL Section ## 
# 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\MPEG2Dec3.dll") 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\GripFit_YV12.dll") 
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\UnDot.dll")
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\atc.dll")
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\blockbuster.dll")
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\DctFilter.dll")
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\Deen.dll")
LoadPlugin("D:\KVCD\AviSynth\AviSynth 2.5\plugins\Convolution3DYV12.dll")

AviSource("R:\AVIs\Sample.avi") 
BlindPP(cpu=4) 
Blockbuster(method="noise",detail_min=1,detail_max=3,variance=0.1,seed=1) 
Convolution3D(1, 6, 12, 6, 8, 2.8, 0) 
GripCrop(352, 288, overscan=2, source_anamorphic=false)
GripSize(resizer="LanczosResize") 
Undot() 
TemporalSoften(2,7,7,3,2) 
DCTFilter(1,1,1,1,1,1,0.5,0) 
#Blockbuster(method="noise",detail_min=1,detail_max=10,variance=0.3,seed=5623) 
GripBorders()
And.. I used CQMatic to do the CQ prediction (X3 prediction). It took 86minutes for it to decide a CQ. The final CQ I got was 89.6. I used it to encode the movie. I got a 660MB .m1v file (still shorter than expected). So, I converted the source Wav file to 160kbps, 48KHz (is this ok.. or do I need to convert it to 44.1Khz?) MP2 file and in the end, I got a MPEG file of size 783 MB. This is a lot better result than my previous tries.

What I need to know is... is there a way I can reduce the prediction time when using CQMatic? Or, is there an alternative?. I still havent looked up the ping-pong method described in the link given by Prodater.

Thanks
__________________
-p2p hvnt3r-
Reply With Quote
  #9  
03-31-2004, 12:53 PM
Dialhot Dialhot is offline
Free Member
 
Join Date: May 2003
Posts: 10,463
Thanks: 0
Thanked 0 Times in 0 Posts
I guess that all filesize are negatives in the log of cqmatic and that means that the prediction failed !

That is what it took so much time and you ended up with a CQ of 89.

Please read CARREFULLY the hints given with CQmatic.
Reply With Quote
  #10  
03-31-2004, 01:10 PM
p2phunter p2phunter is offline
Free Member
 
Join Date: Mar 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
is the CQMatic Log file stored somewhere? I cant find it!

The size of the sample created by CQMatic during its last prediction (with CQ 89.7) was 38.9 MB (named as Sample.m1v.sample) . Does this information help in anyway?

And.. I think the prediction was actually successful!
__________________
-p2p hvnt3r-
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Ping-pong prediction vs Long-short prediction Abond Avisynth Scripting 136 07-05-2005 02:13 PM
DVD2SVCD: CQ prediction problems paolo Video Encoding and Conversion 0 01-12-2005 04:08 AM
KVCD: problems with the prediction phase prior to encoding in TMPENc? Blubear Video Encoding and Conversion 5 07-06-2004 11:52 AM
Bitrates: File size prediction problems Drisanna Video Encoding and Conversion 23 04-29-2004 08:54 AM
Bitrates: KDVD CQ Prediction Problems nicksteel Video Encoding and Conversion 1 08-15-2003 11:26 AM

Thread Tools



 
All times are GMT -5. The time now is 10:55 AM  —  vBulletin © Jelsoft Enterprises Ltd