digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: Simplify your AVS scripts (http://www.digitalfaq.com/archives/avisynth/2794-avisynth-simplify-avs.html)

ARnet_tenRA 02-26-2003 11:43 AM

Simplify your AVS scripts
 
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

rendalunit 02-26-2003 02:27 PM

Thanks Tenra!

This should save a lot of cutting and pasting 8)

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

Also the Sampler function is different 8O

did i miss something in the file prediction forum? :?: 8O 8O

ren

ARnet_tenRA 02-26-2003 02:47 PM

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

rendalunit 02-26-2003 04:16 PM

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 8) I don't see any reason to keep the other prediction funtion anymore so that's less typing there :D

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

thx,
ren

SansGrip 02-26-2003 04:43 PM

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 ;).

SansGrip 02-26-2003 04:44 PM

BTW, what is Predict2 and where can I download it? :)

rendalunit 02-26-2003 04:57 PM

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

ARnet_tenRA 02-26-2003 05:10 PM

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 8) I don't see any reason to keep the other prediction funtion anymore so that's less typing there :D

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! :oops: Pardon me SansGrip! :D 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! :D

SansGrip 02-26-2003 05:18 PM

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 :mrgreen:.

SansGrip 02-26-2003 05:20 PM

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.

ARnet_tenRA 02-26-2003 05:26 PM

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

rendalunit 02-26-2003 11:04 PM

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


ARnet_tenRA 02-27-2003 07:53 AM

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

ozjeff99 02-27-2003 08:37 AM

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

ARnet_tenRA 02-27-2003 09:56 AM

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=128)

Regards, Tenra

Smoochie3 02-27-2003 06:16 PM

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

ARnet_tenRA 02-27-2003 07:42 PM

You only need the Predict2(blah, blah, blah) :wink:

-Tenra

Smoochie3 02-27-2003 07:56 PM

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?

ARnet_tenRA 02-27-2003 11:03 PM

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

jorel 02-28-2003 03:12 AM

Quote:

Originally Posted by ARnet_tenRA
You only need the Predict2(blah, blah, blah) :wink:

-Tenra

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

how to use it all,ARnet_tenRA?

in special the "(blah, blah, blah)" 8O
thanks


All times are GMT -5. The time now is 02:14 AM  —  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.