Quantcast Avisynth: Simplify Your AVS Scripts - digitalFAQ.com Forums [Archives]
  #1  
02-26-2003, 11:43 AM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
If you want to save some typing in the future, try using the Import function the next time you make an avisynth script.

Here is a sample script I have created where all of the LoadPlugin lines have been moved into a functions file.

Code:
Import ("C:\filters\functions.h")

Mpeg2Source("D:\videos\testmov.d2v")
LegalClip()

GripCrop( width=528, height=480, overscan=2 )
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()
LegalClip()
#Prediction(SampleSize=10, CQ=50, MinAudioBitrate=112)
Predict2(AudioBitrate=112, Samp1=10, CQ1=50, Samp2=13, CQ2=53.8)
Sampler()
Here is the functions.h file that I use.

Regards, Tenra
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  
02-26-2003, 02:27 PM
rendalunit rendalunit is offline
Free Member
 
Join Date: Apr 2002
Location: san jose, Ca
Posts: 1,148
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Tenra!

This should save a lot of cutting and pasting

I'm going to have to try out your predict 2 function- how come you didn't share this before? just kidding

Also the Sampler function is different

did i miss something in the file prediction forum?

ren
Reply With Quote
  #3  
02-26-2003, 02:47 PM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
I haven't posted yet because I only just finished those functions.

The sampler is my first attempt at creating a function. The benefit of this one over the sampler.dll is that the formula for prediction is always (samplesize * 60) no matter the framerate.

The predict2 function allows you to base future guesses on 2 samples instead of just one.

Regards, Tenra
Reply With Quote
  #4  
02-26-2003, 04:16 PM
rendalunit rendalunit is offline
Free Member
 
Join Date: Apr 2002
Location: san jose, Ca
Posts: 1,148
Thanks: 0
Thanked 0 Times in 0 Posts
I tried your Predict2 function and it works great! You found the workaround for the division by zero error when the cq or sample size =0 I don't see any reason to keep the other prediction funtion anymore so that's less typing there

I don't know how to use your sampler function though- should i set the length parameter {i.e. sampler(length=24)}?

thx,
ren
Reply With Quote
  #5  
02-26-2003, 04:43 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ARnet_tenRA
The benefit of this one over the sampler.dll is that the formula for prediction is always (samplesize * 60) no matter the framerate.
If you're going to release this filter I'd be grateful if you'd call it something other than "Sampler" to avoid confusion .
Reply With Quote
  #6  
02-26-2003, 04:44 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
BTW, what is Predict2 and where can I download it?
Reply With Quote
  #7  
02-26-2003, 04:57 PM
rendalunit rendalunit is offline
Free Member
 
Join Date: Apr 2002
Location: san jose, Ca
Posts: 1,148
Thanks: 0
Thanked 0 Times in 0 Posts
hi SansGrip,

Predict2 is in the function.h file Tenra posted above
Code:
#------------------------------# 
# Prediction Function 2        # 
#------------------------------# 
function Predict2 (clip c, string "movie", float "cds", int "cdtime", float "factor", float "Samp1", float "Samp2", float "CQ1", float "CQ2", int "AudioBitrate") 
{ 
movie = default(movie,"No_Title_Defined") 
factor = default(factor,1) 
cds = default(cds,1) 
cdtime = default(cdtime,80) 
Samp1 = default(Samp1,0) 
Samp2 = default(Samp2,0) 
CQ1 = default(CQ1,0) 
CQ2 = default(CQ2,0) 
AudioBitrate = default(AudioBitrate,128)

mSeconds  = framecount(c)/framerate(c) 
mFrames  = framecount(c) 
sFrames = framecount(Sampler(c)) 
CDkBytes = (((cdtime*10)-5)*1024)*cds 
Desired = (((((CDkBytes-((AudioBitrate/8)*mSeconds))*sFrames)/mFrames)*factor))/1000 
NewCQ=(samp1==0)?50:(CQ1+((CQ2-CQ1)*(Desired-Samp1)/(Samp2-Samp1)))

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(mFrames), 80,60). 
\Subtitle("Sample Frames : " + String(sFrames), 80,80). 
\Subtitle("Time (sec) : " + String(round(mSeconds)), 80,100). 
\Subtitle("Time (min) : " + String(round(mSeconds/60)), 80,120). 

\Subtitle("Sample 1 = "+LeftStr(String(Samp1),5)+" :   CQ 1 = " + LeftStr(String(CQ1),4), 270,60,text_color=$FF0000). 
\Subtitle("Sample 2 = "+LeftStr(String(Samp2),5)+" :   CQ 2 = " + LeftStr(String(CQ2),4),270,80,text_color=$FF0000). 
\Subtitle("Min. Audio Bitrate : "+ String(AudioBitrate)+" kbps",270,100,text_color=$FF0000). 
\Subtitle("Desired Sample Size (mb) : " + LeftStr(String(Desired),5),270,120,text_color=$FF0000). 
\Subtitle("Try New CQ = " + LeftStr(String(NewCQ),5),270,140,text_color=$FF0000). 

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

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

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

\LanczosResize(width(c), height(c)) 
return d+c+d 
}
this evolved from this thread

ren
Reply With Quote
  #8  
02-26-2003, 05:10 PM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by rendalunit
I tried your Predict2 function and it works great! You found the workaround for the division by zero error when the cq or sample size =0 I don't see any reason to keep the other prediction funtion anymore so that's less typing there
Thanks!!!

Quote:
Originally Posted by rendalunit
I don't know how to use your sampler function though- should i set the length parameter {i.e. sampler(length=24)}?
I only put the length parameter in there so that it wouldn't break previous scripts. I have now renamed this function to SampleClip and removed the length argument altogether. All you need to do is write SampleClip()

Quote:
Originally Posted by SansGrip
If you're going to release this filter I'd be grateful if you'd call it something other than "Sampler" to avoid confusion .

BTW, what is Predict2 and where can I download it?
Oops! Pardon me SansGrip! This wasn't really meant for distribution yet, but since I posted my actual functions it came out. I have renamed it to SampleClip to avoid confusion in the future.

Lastly, I posted the url to my functions in the original post. Here it is again. http://users.bwsys.net/~djvande/functions.h

Enjoy!
Reply With Quote
  #9  
02-26-2003, 05:18 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ARnet_tenRA
This wasn't really meant for distribution yet, but since I posted my actual functions it came out. I have renamed it to SampleClip to avoid confusion in the future.
Thanks -- now neither of us will receive bug reports about the other's work .
Reply With Quote
  #10  
02-26-2003, 05:20 PM
SansGrip SansGrip is offline
Free Member
 
Join Date: Nov 2002
Location: Ontario, Canada
Posts: 1,135
Thanks: 0
Thanked 0 Times in 0 Posts
By the way, did you check your SampleClip produces exactly the right frame count? One of the reasons I wrote Sampler is because SelectEvery seemed to be out by a significant number of frames, while Sampler produces exactly (length * samples) frames.
Reply With Quote
  #11  
02-26-2003, 05:26 PM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by SansGrip
By the way, did you check your SampleClip produces exactly the right frame count? One of the reasons I wrote Sampler is because SelectEvery seemed to be out by a significant number of frames, while Sampler produces exactly (length * samples) frames.
Actually I noticed that this does product slightly more frames than Sampler. But I haven't noticed any problems with prediction as long as I use the formula: FinalSize=SampleSize*60 and don't use the 0.98 adjustment factor. ie: it's better to have those extra frames to eliminate the previously needed factor.

Regards, Tenra
Reply With Quote
  #12  
02-26-2003, 11:04 PM
rendalunit rendalunit is offline
Free Member
 
Join Date: Apr 2002
Location: san jose, Ca
Posts: 1,148
Thanks: 0
Thanked 0 Times in 0 Posts
hey Tenra,

There's a little bug in the Predict2 function that when both samples are the same size then the newCQ is displayed funny (i think because of division by 0)- i know both samples shouldn't be the same size but just to keep avisynth from possibly crashing i added these lines:
Code:
difSamples = Samp2 - Samp1
difSamples = (difSamples==0)? 1: difSamples
NewCQ=(samp1==0)?50:(CQ1+((CQ2-CQ1)*(Desired-Samp1)/(difSamples)))
Reply With Quote
  #13  
02-27-2003, 07:53 AM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks ren! I have added it to my script. I also now have functions.h as part of my sig so it should be easier to grab in the future.

Regards, Tenra
Reply With Quote
  #14  
02-27-2003, 08:37 AM
ozjeff99 ozjeff99 is offline
Free Member
 
Join Date: May 2002
Location: Sydney, Australia
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Tenra

Not sure how to use your predict2 function, the arguments etc. Could you supply a bit more explanation on how to set it up and what it produces.

Thanks
Jeff
Reply With Quote
  #15  
02-27-2003, 09:56 AM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Jeff,

Here is an explanation of the predict2 function:

First your avs script should look like this.
Code:
Import ("C:\filters\functions.h") 

Mpeg2Source("D:\videos\testmov.d2v") 

# ##########
#Enter your filters here
# ##########

Predict2(AudioBitrate=112, Samp1=10, CQ1=50, Samp2=13, CQ2=53.8) 
SampleClip()
Here are the arguments for the Predict2 function: (all are optional)

movie="moviename" #Enter the name of the movie(Default=No_Title_Defined)
cds= #Enter the number of CDs you are targeting (Default=1)
cdtime= #Enter whether you have 74 or 80 minute CD (Default=80)
factor= #Enter the scale factor for sample sizes (Default=1)
Samp1= #Enter the size in MB of your first sample created
Samp2= #Enter the size in MB of your second sample created
CQ1= #Enter the CQ used to create the first sample
CQ2= #Enter the CQ used to create the second sample
AudioBitrate= #Enter the Bitrate you will encode the audio at (Default=12

Regards, Tenra
Reply With Quote
  #16  
02-27-2003, 06:16 PM
Smoochie3 Smoochie3 is offline
Free Member
 
Join Date: Jun 2002
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
OK, i'm confused.

Should i have the

Prediction(blah, blah, blah)

AND the

Predict2(blah, blah, blah)

in my script, or just the

Predict2(blah, blah, blah)?
Reply With Quote
  #17  
02-27-2003, 07:42 PM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
You only need the Predict2(blah, blah, blah)

-Tenra
Reply With Quote
  #18  
02-27-2003, 07:56 PM
Smoochie3 Smoochie3 is offline
Free Member
 
Join Date: Jun 2002
Posts: 129
Thanks: 0
Thanked 0 Times in 0 Posts
So this:

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

movie="Ronin"
cds=1
cdtime=80
factor=0.98
CQ1=0
Samp1=0
CQ2=0
Samp2=0
MinAudioBitrate=128


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()

Predict2(movie, cds, cdtime, factor, Samp1, CQ1, Samp2, CQ2, MinAudioBitrate)
SampleClip()
Should work?

I encode the first time and fill in samp1= and cq1=, encode a second time and fill in samp2= and cq2= and it will then tell me what final cq to use?
Reply With Quote
  #19  
02-27-2003, 11:03 PM
ARnet_tenRA ARnet_tenRA is offline
Free Member
 
Join Date: Jan 2003
Location: Illinois, USA
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Yes. That's the idea. The only thing is that you have some of the parameters out of order. Here is the correct order:
Code:
Predict2 (clip, movie, cds, cdtime, factor, Samp1, Samp2, CQ1, CQ2, AudioBitrate)
The formula it uses is good but not perfect so you may have to replace the Samp1 and CQ1 when you have encoded another test.

When you have all 0s for the first run it will always suggest CQ 50.

After you have filled in the Samp1 and CQ1 then it will try to predict a better CQ.

When you have filled in Samp2 and CQ2 then it will use both and find a value in between proportionate to the difference between the two.

Code:
Example: Desired sample size will be 12.16MB
Samp1=0 CQ1=0 : Samp2=0 CQ2=0
Predict2 will suggest CQ 50

Samp1=10 CQ1=50 : Samp2=0 CQ2=0
Predict2 will suggest CQ 60.81

Samp1=10 CQ1=50 : Samp2=13 CQ2=60.81
Predict2 will suggest CQ 57.79
In this example I may have to encode one more sample if 57.79 isn't close enough for me. I would just replace the parameters for Samp1 and CQ1 with the values from the CQ57.79 sample.

Regards, Tenra
Reply With Quote
  #20  
02-28-2003, 03:12 AM
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
Quote:
Originally Posted by ARnet_tenRA
You only need the Predict2(blah, blah, blah)

-Tenra

ok,laugh but lost.
i was out,very busy and lost something (or all)!

how to use it all,ARnet_tenRA?

in special the "(blah, blah, blah)"
thanks
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Avisynth: What scripts are you using? rainer Avisynth Scripting 9 04-17-2007 12:51 AM
what are AviSynth Scripts? krustytheklown Avisynth Scripting 11 08-10-2003 08:43 PM
Sizes with scripts for avisynth 2.08 vs avisynth 2.52 ? jorel Avisynth Scripting 24 07-10-2003 09:57 PM
Avisynth: Can Avisynth chain scripts? MrTibs Avisynth Scripting 6 06-19-2003 06:28 PM
Avisynth: My avisynth scripts do not work ! Kane Avisynth Scripting 2 04-16-2003 03:40 AM

Thread Tools



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