digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: Little optimizations in optimal script (http://www.digitalfaq.com/archives/avisynth/4269-avisynth-little-optimizations.html)

Dialhot 07-01-2003 05:09 AM

Little optimizations in optimal script
 
Hello guys,

The optimal script does a really good job, but it can do it a little faster :!:

ORIGINAL
Code:

MaxTreshold = 1.50
nf =  0 # Current frame.

Mpeg2Source("Your_D2V_Source_Here")

undot()
Limiter()
asharp(2, 4)
GripCrop(Your_GripCrop_Parameters_Here)
GripSize(resizer="BicubicResize")
STMedianFilter(8, 32, 0, 0 )
MergeChroma(blur(MaxTreshold))
MergeLuma(blur(0.2))

ScriptClip("nf = YDifferenceToNext()"+chr(13)+ "nf > 2 ? \
unfilter( -(fmin(round((nf/0.5)), 100)), -(fmin(round((nf/0.5)), 100)) ) : \
TemporalSoften(4, round(1/nf) , round(3/nf) ,0, 2) ")

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

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

OPTIMIZED
Code:

nf =  0 # Current frame.

Mpeg2Source("Your_D2V_Source_Here")

undot()
Limiter()
asharp(2, 4)
GripCrop(Your_GripCrop_Parameters_Here)
GripSize(resizer="BicubicResize")
STMedianFilter(8, 32, 0, 0 )
MergeChroma(blur(1.50))
MergeLuma(blur(0.2))

ScriptClip("nf = round(YDifferenceToNext())"+chr(13)+ "nf > 2 ? \
unfilter( -(fmin(nf*2, 100)), -(fmin(nf*2, 100)) ) : \
TemporalSoften(4, round(1/nf) , round(3/nf) ,0, 2) ")

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

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

1/ "nf*2" is equivalent to "nf/0.5" but is faster as we use only int
2/ fmin is called only with int values so why declare f1 and f2 as float ?

My tests on a 5 min video : 31'28s for encoding with the "original" script, 31'04s with the new one

I also made test with temporalcleaner insteed of temporalsoften, and is A LOT faster : 20'27s for encoding the same video.
(sample size was quite the same)

I used this parameters :
Code:

temporalcleaner(fmin(3+nf,7),fmin(8+nf,15))
I'm opened to suggestion on the visual result obtained with this filter :idea: [/code]

Jellygoose 07-01-2003 06:45 AM

Can you post the full script made with TemporalCleaner please? I'd like to test it against the current optimal script!

Dialhot 07-01-2003 07:06 AM

Quote:

Originally Posted by Jellygoose
Can you post the full script made with TemporalCleaner please? I'd like to test it against the current optimal script!

Code:

nf =  0 # Current frame.

Mpeg2Source("Your_D2V_Source_Here")

undot()
Limiter()
asharp(2, 4)
GripCrop(Your_GripCrop_Parameters_Here)
GripSize(resizer="BicubicResize")
STMedianFilter(8, 32, 0, 0 )
MergeChroma(blur(1.50))
MergeLuma(blur(0.2))

ScriptClip("nf = round(YDifferenceToNext())"+chr(13)+ "nf > 2 ? \
unfilter( -(fmin(nf*2, 100)), -(fmin(nf*2, 100)) ) : \
temporalcleaner(fmin(3+nf,7),fmin(8+nf,15)) ")

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

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


kwag 07-01-2003 09:10 AM

Hi Dialhot,

Thanks for the update :)
Yep, you sure got that right :!:
I'm updating the script now with your changes:
Code:

ScriptClip("nf = round(YDifferenceToNext())"+chr(13)+ "nf > 2 ? \
unfilter( -(fmin(nf*2, 100)), -(fmin(nf*2, 100)) ) : \
TemporalSoften(4, round(1/nf) , round(3/nf) ,0, 2) ")

But I'll hold back on the temporalcleaner until I make more tests to see if prediction is not changed, and also if it does weird interactions like the problems I had before with the mergeluma, etc., when they were set with adaptive (dinamic) values.

-kwag

audi2honda 07-01-2003 10:41 AM

Kwag I noticed you didn't change the functions to integer instead of float like in dialhots example. In the sticky you only changed the adaptive portion. Did you mean to do this?

jorel 07-01-2003 11:18 AM

audi2honda my friend,
Kwag is testing the news like me.

i trust in Phil and Kwag too,
he only do tests cos he want to show the best for us all.
he will post precise results :!:

:wink:

ovg64 07-01-2003 11:33 AM

Quote:

Originally Posted by audi2honda
Kwag I noticed you didn't change the functions to integer instead of float like in dialhots example. In the sticky you only changed the adaptive portion. Did you mean to do this?

Yes I see it to but not in the sticky: Latest Script :roll:

kwag 07-01-2003 11:37 AM

Quote:

Originally Posted by audi2honda
Kwag I noticed you didn't change the functions to integer instead of float like in dialhots example. In the sticky you only changed the adaptive portion. Did you mean to do this?

No, I forgot :oops:
Doing it now :!:

Thanks and thanks ovg64 for the PM too ;)
-kwag

audioslave 07-01-2003 12:26 PM

WOW! 8O
I tested to run a full prediction just to see the speed improvement. AMAZING! The prediction used to take about 7 minutes for this movie (I Spy) and with this new optimization it only takes 3.5 minutes!!! I couldn't believe my eyes! :D

kwag 07-01-2003 12:31 PM

Yep, there's a BIG difference in speed between floating point to integer math :wink:

To Dialhot:
Have a beer :mrgreen:

-kwag

jorel 07-01-2003 12:37 PM

8O

yeah, jet script!
:)

editing:
predictions..

old script:
Tries : 6
Total Time For Predicition: 00:04:04

new script:
Tries : 7
Total Time For Predicition: 00:03:49

one more "try" and with less total time.
:)

audi2honda 07-01-2003 01:21 PM

I'm only about 15 minutes into a new encode, but according to the time counter in TMPGEnc my encode has gone from 3 hours to 2:15 with the latest integer changes :!: :!:

And the remaining time clock is decreasing faster then real time. 8O 8O :D

ovg64 07-01-2003 01:38 PM

Yes encoding right now n have 2hrs.50 min. to the goal,
looks like we may have to raise the max speed limit again :!: :mrgreen:

plautzer 07-01-2003 02:55 PM

how is that possible??
Ok, I got a 1,4 ghz amd, but it takes at least 10 hr to encode muvie!!
Do u think that tuning could help me out??

Plautzer

audi2honda 07-01-2003 03:38 PM

Well my encode just finished and this was using a 70% film 30% NTSC video hybrid source with telecide and decimate. I used 48 frame samples and 2 samples per minute which slowed down prediction a lot, but with this hybrid source I thought it might help.

Well the results are in :!: With the latest Optimal script today with the int variables I got 100% accuracy on my prediciton that when muxed came to exactly 795MB 8O 8O :!: :!: :!: :D

Oh and not to mention it ran blazingly fast

Plautzer. my times are for a P4 2.8ghz machine with ddr266.

I also have a 1.8ghz machine at home that takes about 5 hours. Yours should be faster. Is it a P4?

ovg64 07-01-2003 04:10 PM

Quote:

Originally Posted by plautzer
how is that possible??
Ok, I got a 1,4 ghz amd, but it takes at least 10 hr to encode muvie!!
Do u think that tuning could help me out??

Plautzer

Well my Deal here is an Athlon xp which gets up to 1.46Gigs with out clocking it, this encode when finish is going to be 4hrs. 6min. long... :mrgreen: , Monsters Inc. 93 min Toon.

plautzer 07-01-2003 04:10 PM

I got a AMD athlon 1600 xp+!!
I guess a gotta upgrade it soon!!
I encode it on 2 cds, i guess it take that double es as long!!

plautzer

ARAGORN 07-01-2003 04:11 PM

Hi

There's no difference for me in speed :(

I've got an athlon 2400, 512M0 DRR and windows xp

Kwag, what's the problem here

I'm using pal

Another question: when i encode with tok the dc component precision is set to 9 in tmpgenc. I'm using your settins tab for tok. Should not be 8?

ARAGORN

audi2honda 07-01-2003 04:14 PM

Quote:

Originally Posted by plautzer
I got a AMD athlon 1600 xp+!!
I guess a gotta upgrade it soon!!
I encode it on 2 cds, i guess it take that double es as long!!

plautzer

The number of CDs shouldn't have much of an impact on encoding time.

kwag 07-01-2003 04:14 PM

Quote:

Originally Posted by ARAGORN

Another question: when i encode with tok the dc component precision is set to 9 in tmpgenc. I'm using your settins tab for tok. Should not be 8?

If you are encoding MPEG-1, it's always 8 bits. The DC component will be shadowed.

-kwag

plautzer 07-01-2003 04:19 PM

Quote:

Originally Posted by ovg64
Well my Deal here is an Athlon xp which gets up to 1.46Gigs with out clocking it, this encode when finish is going to be 4hrs. 6min. long... :mrgreen: , Monsters Inc. 93 min Toon.

Im encoding American History X right ( ToK (MPEG-1 704x576 25fps CQ 90)) now, on 2 CDs and Its gonna take my at least 10 hours!!1


What do u mean with "clocking it" ???

Plautzer

ovg64 07-01-2003 04:33 PM

Quote:

Originally Posted by plautzer
Quote:

Originally Posted by ovg64
Well my Deal here is an Athlon xp which gets up to 1.46Gigs with out clocking it, this encode when finish is going to be 4hrs. 6min. long... :mrgreen: , Monsters Inc. 93 min Toon.

Im encoding American History X right ( ToK (MPEG-1 704x576 25fps CQ 90)) now, on 2 CDs and Its gonna take my at least 10 hours!!1


What do u mean with "clocking it" ???

Plautzer

Ask Jorel about the clocking deal he will explain it better :P

i bolive 704x576 pal would make a differencs in time , movie just
finish now I heard the ding by Tmpeg... hehe i was encoding at 528x480
that would be much faster than 704x576. :wink:

edmund 07-01-2003 04:43 PM

i am having the same problem.. with tok it took 3 tries to get my cq but it took 12 minutes what the heck is that. what do i need to do to clock it?? ( and what exactly is clocking it) thanks ??

kwag 07-01-2003 04:45 PM

They are talking about "Overclocking". Not clocking. It's when you increase the CPU clock on your machine over it's designed limit. That's why it's called OverClocking.

-kwag

audi2honda 07-01-2003 04:46 PM

He's talking about overclocking his processor to get more speed. That's a whole nother can of worms. www.anandtech.com

plautzer 07-01-2003 04:46 PM

Aight ill gonna ask jorel,
but I have another problem, which i never had when I was using the old avisynth!!
During the encoding, when I go off the internet.. my computer reboots!!
That piss me off, cuz soemtime its right before the ende!!

Did anybody have a problem like that??

Thx guys

Plautzer

ovg64 07-01-2003 04:51 PM

Quote:

Originally Posted by kwag
They are talking about "Overclocking". Not clocking. It's when you increase the CPU clock on your machine over it's designed limit. That's why it's called OverClocking.

-kwag

Right Kwag, i dont have the board nor the memory speed to over joy :hihi: this thing

audi2honda 07-01-2003 04:53 PM

Quote:

Originally Posted by ovg64
Right Kwag, i dont have the board nor the memory speed to over joy :hihi: this thing

Based on my results so far with today's script I feel like I just got a CPU upgrade for free :) :)

kwag 07-01-2003 04:55 PM

Quote:

Originally Posted by audi2honda

Based on my results so far with today's script I feel like I just got a CPU upgrade for free :) :)

Based on your results so far, I feel like I need to pay for a CPU upgrade :!: :mrgreen:

-kwag

ovg64 07-01-2003 04:56 PM

Quote:

Originally Posted by plautzer
Aight ill gonna ask jorel,
but I have another problem, which i never had when I was using the old avisynth!!
During the encoding, when I go off the internet.. my computer reboots!!
That piss me off, cuz soemtime its right before the ende!!

Did anybody have a problem like that??

Thx guys

Plautzer

Sound like a setting in windows that when the computer is about to crash it will reboot instead. :idea:

Dialhot 07-01-2003 06:03 PM

I apologize for this "divide by zero" error, I should have check this.

But this point me to an other problem that the solution found by Kwag introduces :

round(YDifferenceToNext()+1) always gives values >= 1

So round(1/nf) and round(3/nf) will produce only TWO values : 0 or 1.

I'm sorry, I didn't saw that before :BangHead:

I think that the better solution (for speed and accuracy) is :

Code:

ScriptClip("nf = YDifferenceToNext()"+chr(13)+ "nf >= 2 ? \
unfilter( -(fmin(round(nf)*2, 100)), -(fmin(round(nf)*2, 100)) ) : \
TemporalSoften(4, round(1/nf) , round(3/nf) ,0, 2) ")

(until Kwag give us its advice on temporalcleaner ;-))

Grantman 07-01-2003 06:14 PM

Latest changes = less compression?
 
I just made a test using the latest changes to the optimal script. I have a 21 second clip for testing. (It is the opening "couch" sequence from an episode of The Simpsons).

The end result is going to 352x240 but using the KVCD3 template. I only change the resolution.

The latest script as of Sunday produced a file size of 2,206KB. I ran the exact same project but with the changed script as of today and the file size was 2,384KB.

I did not notice an perceptable quality difference in VirtualDub or by playing them on my TV. (Using Nero and burning as VCD).

I understand the script is really optimized for DVD movies not animation. I just though the file size change was interesting.


Grantman

Dialhot 07-01-2003 06:47 PM

Re: Latest changes = less compression?
 
Quote:

Originally Posted by Grantman
The latest script as of Sunday produced a file size of 2,206KB. I ran the exact same project but with the changed script as of today and the file size was 2,384KB

Yes, that a logical result of the problem I mentioned just above : with my old suggestion, temporalcleaner works with only two values : 0 and 1. In other words : does'nt have a great impact.

Try with the ultimate modifications I did in my post of 12:03 am, and tell us.

kwag 07-01-2003 09:33 PM

Script corrected. I guess I wasn't that tired after all earlier this morning, but I wasn't too awake :)
First I saw the error, then I thought It was me. As a rule, I shouldn't do math early in the morning :lol:

Thanks Phil ;)
-kwag

audioslave 07-03-2003 04:48 PM

@Dialhot,
I can't get it to work. Could you please look at my script and tell me what's wrong?

Quote:

nf = 0 # Current frame.

Mpeg2Source("D:\DVD Rips\Strange Days\Strange Days.d2v")

undot()
Limiter()
asharp(2, 4)
GripCrop(480, 480, source_anamorphic=false)
GripSize(resizer="BicubicResize")
STMedianFilter(8, 32, 0, 0 )
MergeChroma(blur(1.50))
MergeLuma(blur(0.2))

ScriptClip("nf = YDifferenceToNext()"+chr(13)+ "nf >= 2 ? \
unfilter( -(fmin(round(nf)*2, 100)), -(fmin(round(nf)*2, 100)) ) : \
temporalcleaner(fmin(3+nf,7),fmin(8+nf,15)) ")

#BlockBuster(method="noise", detail_min=1, detail_max=10, variance=0.7, seed=1) # For 352x encodes
BlockBuster(method="noise", detail_min=1, detail_max=10, variance=0.4, seed=1) # For 480x encodes

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

function fmin(int f1, int f2) {
return (f1<f2) ? f1 : f2
}
When I load this script in ToK and flip to the video tab it says:
Quote:

Script error: Invalid arguments to "fmin"
([ScriptClip], line 4)
And I have no clue to what that means. 8O

kwag 07-03-2003 05:28 PM

The function fmin() is expecting only integer values. You are sending floating point values in the temporalcleaner function :!:
You need to "round" the values in the function call. Just like in the "unfilter" line.

-kwag

audioslave 07-03-2003 05:32 PM

8O Say what? Could you please show how the line is supposed to look? As I said earlier: I'm no programmer... :wink:

kwag 07-03-2003 06:03 PM

It should look like this:

Code:

temporalcleaner(fmin(round(3+nf), 7), fmin(round(8+nf), 15)) ")
-kwag

audioslave 07-03-2003 06:12 PM

Thanks a lot kwag! I really wanted to try the MAS with TemporalCleaner but I couldn't figure out what was wrong. You're my hero! The Man, The Myth, The Legend - KWAG! :D

jorel 07-03-2003 06:26 PM

editing:

Phil post this lines and works fine,seems with more clean colors:

ScriptClip("nf = YDifferenceToNext()"+chr(13)+ "nf >= 2 ? \
unfilter( -(fmin(round(nf)*2, 100)), -(fmin(round(nf)*2, 100)) ) : \
TemporalSoften(4, round(1/nf) , round(3/nf) ,0, 2) ")


ps:
i was posted only part of this lines,now are complete!
:)


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

Site design, images and content © 2002-2026 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2026 Jelsoft Enterprises Ltd.