Quantcast Avisynth: Question on Conditional Operator - digitalFAQ.com Forums [Archives]
  #1  
06-17-2003, 04:28 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
@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
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  
06-17-2003, 07:15 PM
Grantman Grantman is offline
Free Member
 
Join Date: Sep 2002
Location: Northfield, IL
Posts: 102
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Grantman Send a message via AIM to Grantman Send a message via MSN to Grantman Send a message via Yahoo to Grantman
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 )

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
Reply With Quote
  #3  
06-17-2003, 08:35 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #4  
06-18-2003, 05:09 AM
sh0dan sh0dan is offline
Free Member
 
Join Date: Mar 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
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.
__________________
Regards, sh0dan // VoxPod
Reply With Quote
  #5  
06-18-2003, 11:04 AM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #6  
06-18-2003, 12:25 PM
sh0dan sh0dan is offline
Free Member
 
Join Date: Mar 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Fast solution:

sharp = asharp(-2,0)
conditionalfilter(last,sharp,last, "nf",">", "scd_trigger")
__________________
Regards, sh0dan // VoxPod
Reply With Quote
  #7  
06-18-2003, 02:07 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by sh0dan
Fast solution:

sharp = asharp(-2,0)
conditionalfilter(last,sharp,last, "nf",">", "scd_trigger")
WAY more elegant
Thanks sh0dan
Updating script in a few moments

-kwag
Reply With Quote
  #8  
06-18-2003, 02:57 PM
Anerboda Anerboda is offline
Free Member
 
Join Date: Mar 2003
Location: Denmark
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #9  
06-18-2003, 02:58 PM
sh0dan sh0dan is offline
Free Member
 
Join Date: Mar 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
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.
__________________
Regards, sh0dan // VoxPod
Reply With Quote
  #10  
06-18-2003, 03:03 PM
Anerboda Anerboda is offline
Free Member
 
Join Date: Mar 2003
Location: Denmark
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #11  
06-18-2003, 03:18 PM
sh0dan sh0dan is offline
Free Member
 
Join Date: Mar 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
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.
__________________
Regards, sh0dan // VoxPod
Reply With Quote
  #12  
06-18-2003, 03:43 PM
kwag kwag is offline
Free Member
 
Join Date: Apr 2002
Location: Puerto Rico, USA
Posts: 13,537
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks sh0dan,

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

-kwag
Reply With Quote
  #13  
06-18-2003, 09:21 PM
vhelp vhelp is offline
Free Member
 
Join Date: Jan 2003
Posts: 1,009
Thanks: 0
Thanked 0 Times in 0 Posts
@ 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
Reply With Quote
  #14  
06-18-2003, 09:54 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
vhelp,

this is the thread for last scripts:

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

Reply With Quote
  #15  
06-18-2003, 09:56 PM
vhelp vhelp is offline
Free Member
 
Join Date: Jan 2003
Posts: 1,009
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks pal-Jorel..

-vhelp
Reply With Quote
  #16  
06-18-2003, 10:09 PM
ovg64 ovg64 is offline
Free Member
 
Join Date: Jan 2003
Location: Puerto Rico
Posts: 423
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ovg64
Better yet this is the latest script Vhelp

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
}

#
####
Reply With Quote
  #17  
06-18-2003, 10:29 PM
vhelp vhelp is offline
Free Member
 
Join Date: Jan 2003
Posts: 1,009
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Avisynth: Another Crop and Resize Question (VHS capture) Icarus3000 Avisynth Scripting 3 07-20-2005 03:49 AM
Avisynth: Crop and resize question urban tec Avisynth Scripting 3 06-13-2005 08:28 AM
Avisynth: Conditional User Defined Functions? Prodater64 Avisynth Scripting 12 03-31-2004 11:38 PM
Avisynth: Conditional Variables? Prodater64 Avisynth Scripting 3 03-27-2004 11:25 PM
DVD2Avi - script avisynth et CQ matic. Encore une question spirou Conversion et d'Encodage de Vidéo (Français) 1 02-28-2004 11:16 AM

Thread Tools



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