digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Avisynth Scripting (http://www.digitalfaq.com/archives/avisynth/)
-   -   Avisynth: Question on conditional operator (http://www.digitalfaq.com/archives/avisynth/4038-avisynth-question-conditional.html)

kwag 06-17-2003 04:28 PM

Avisynth: Question on conditional operator
 
@sh0dan,

I have a question, related to the "false" condition on the "?" operator.
If I have a function like this:

ScriptClip("nf > scd_trigger ? asharp( -2,0) : asharp(0,0) )

I am forced to use some valid function on the false part, so it returns a valid "clip". I can't use something like this:

ScriptClip("nf > scd_trigger ? asharp( -2,0) : nop() )

which is what I really want to do. That is, in this case, I don't want to return anything on the false condition because "asharp" is already applied on a previous function call before that line.

So really I am using asharp(0,0) as a dummy call, but I assume there's some speed penalty because it's actually calling the function asharp instead of calling a null (nop) function.
Is there a way around this, or some function I can call instead of nop() that doesn't cause a performance hit, and just returns nothing :?:

-kwag

Grantman 06-17-2003 07:15 PM

2 ideas?
 
What about trying to call the clip itself "nf" as the false condition? Instead of the false statement being a valid function maybe it could be the unmodified starting clip variable "nf".

Or... you might be able to rearrange the logic. Instead of having the ScriptClip statement carrying the false condition you could write the statement such that the positive was something like: ScriptClip(nf, "asharp(-2,0)).

The idea would be to bypass the limitation of how the script is written so that you COULD use nop() as the false condition? The entire ScriptClip function would be the positive and nop() would be the negative. ConditionalFilter might work.

(I wish I was fluent enough with the Avisynth scripting to write a complete example :oops: )

Using this syntax (from the Avisynth.org site):

ConditionalFilter(clip testclip, clip source1, clip source2, string filter, string operator, string value, [bool show])

It appears you could conditionally apply the asharp(-2,0) on positive and nop() on negative?


Grantman

kwag 06-17-2003 08:35 PM

Re: 2 ideas?
 
Quote:

Originally Posted by Grantman

It appears you could conditionally apply the asharp(-2,0) on positive and nop() on negative?

That's exactly the way I had the script originally written:
ScriptClip("nf > scd_trigger ? asharp( -2,0) : nop() ")

But it doesn't work, because on false conditions, nop() doesn't return a valid clip and issues an AviSynth error.

-kwag

sh0dan 06-18-2003 05:09 AM

Use "return last" instead of nop()

Anyway - unless you are modifying parameters on every frame (which you are not doing in this case), you should use ConditionalFilter - it is much faster than ScriptClip - and more stable.

kwag 06-18-2003 11:04 AM

Thanks sh0dan, that's exactly the thing I was looking for :)
The script now reads:

ScriptClip("nf > scd_trigger ? asharp( -2,0) : last ")

And works like a charm ;)

-kwag

sh0dan 06-18-2003 12:25 PM

Fast solution:

sharp = asharp(-2,0)
conditionalfilter(last,sharp,last, "nf",">", "scd_trigger")

kwag 06-18-2003 02:07 PM

Quote:

Originally Posted by sh0dan
Fast solution:

sharp = asharp(-2,0)
conditionalfilter(last,sharp,last, "nf",">", "scd_trigger")

WAY more elegant 8)
Thanks sh0dan :D
Updating script in a few moments :!:

-kwag

Anerboda 06-18-2003 02:57 PM

When I load a script with this new condionalfilter I'm getting an error in this line:
Quote:

sharp = asharp(-2,0)
Quote:

Script error: Invalid arguments to function "asharp"
...this is what I get when i open the script in windows media player :?:

Anerboda

sh0dan 06-18-2003 02:58 PM

Just looked at the script - I'm sorry, but it's wrong (it even surprises me it works ;) )

Anyway - sharp is a variable that gets assigned a clip, using the video at the current position. So you must keep the "sharp = " and conditional filter at the same place.

Edit: Oh - you got the error message now ;)

1) Place "sharp = " right before the Conditionalfilter.

The full syntax (without implicit last) is:
Code:

sharp = asharp(last,-2,0) # Sharpen level on scene changes.
So it uses last as the first argument for the filter. This is just a normal variable assignment, just as you always have done.

2) To optimize the first "scriptclip" away, try:
Code:

input = last
sharp_adaptive = scriptclip(input, "asharp( -(fmin((nf/30), 1)), 0 )")
temporal = TemporalSoften(input, 2,7,7,3,2)
Conditionalfilter(input, sharp_adaptive, temporal,"nf = YDifferenceToNext()"+chr(13)+"return nf", ">", "2.5",true)

This should be a bit faster- but try it out, before believing me. I made all implicit lasts explicit, by using "input" instead of nothing.

Anerboda 06-18-2003 03:03 PM

When I put these two lines together it works

Quote:

sharp = asharp(-2,0)
conditionalfilter(last,sharp,last, "nf",">", "scd_trigger")
Like this:
Quote:

#
# Scene change detection - If a scene change is detected, we
# blur heavily. This affects the scene before and the one after the
# scene change, thus providing a softer transition for the encoder instead
# of a sharp "spike".

sharp = asharp(-2,0)
conditionalfilter(last,sharp,last, "nf",">", "scd_trigger")

#
#
#
Is this right??

Anerboda

sh0dan 06-18-2003 03:18 PM

Yes - your filter should now be as before. Conditional filter is faster for choosing between two sources, because the filters themselves does not have to be created for each frame - as scriptclip. It also has the "show" parameter which helps debugging a lot.

This should also avoid potential memory leak explosion in buggy plugins.

PS. I edited the post above.

kwag 06-18-2003 03:43 PM

Thanks sh0dan,

I'll settle for conditionalfilter( last, asharp(-2,0), last, "nf", ">", "scd_trigger" ) just for user's simplicity :wink:
I know, I know, hard coded variables :x, but if the script starts to grow, then we'll all dress it up :D

-kwag

vhelp 06-18-2003 09:21 PM

@ Kwag..

I can't seem to locate this script.. or latest for that matter :(

I want to utilize the latest changes and such, but blind. Is it possible to
move this particular " Motion Adative xxx " script to the top or make
it sticky or something - please ?
Or am I loosing it.

Thanks a bunch whatever the outcome.
-vhelp

jorel 06-18-2003 09:54 PM

vhelp,

this is the thread for last scripts:

http://www.kvcd.net/forum/viewtopic.php?t=3483

:!:

vhelp 06-18-2003 09:56 PM

Thanks pal-Jorel..

-vhelp

ovg64 06-18-2003 10:09 PM

Better yet this is the latest script Vhelp 8O

Quote:

### Ver. June 18, 2003 @20:35 GMT ###
Code:
## DLL Section ##
#
LoadPlugin("C:\Filters25\MPEG2Dec3.dll")
LoadPlugin("C:\Filters25\GripFit_YV12.dll")
LoadPlugin("C:\Filters25\STMedianFilter.dll")
LoadPlugin("C:\Filters25\asharp.dll")
LoadPlugin("C:\Filters25\undot.dll")
#
####

## Defined Variables and Constants ##
#
MaxTreshold = 1.50
scd_trigger = 30 # Scene change trigger value.
nf = 0 # Current frame.
#
####

## Main section and static filters ###
#
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))
#
#

## Dynamic Linear Adaptive Filtering and Scene Change Detection ##
#
# ( Portions from AviSynth's manual ) - This will apply temporalsoften to
# very static scenes, and apply variable blur on moving scenes.
# We also assign a variable - and this is why a line break is inserted:

ScriptClip("nf = YDifferenceToNext()"+chr(13)+ "nf > 2.5 ? asharp( -(fmin((nf/30), 1)), 0 ) : \
TemporalSoften(2,7,7,3,2) ")

#
# Scene change detection - If a scene change is detected, we
# blur heavily. This affects the scene before and the one after the
# scene change, thus providing a softer transition for the encoder instead
# of a sharp "spike".

conditionalfilter( last, asharp(-2,0), last, "nf", ">", "scd_trigger" )

#
#
#

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

#
#
## Functions ###

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

#
####

vhelp 06-18-2003 10:29 PM

Thanks friends.. all :)

Things are working great again, and I'm having fun. Can't wait till the
weekend starts.. after being set back some.

Keep up the good work all.
-vhelp


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