Log in

View Full Version : Logical Operator - "IF" "then" in AviSynth


Atak_Snajpera
11th February 2007, 22:25
Does anybody know how to convert following line to AviSynth script?

IF variable=6 then function() #delphi example

C++ version - if (variable==6) function() doesn't work neither

tsp
11th February 2007, 23:37
depends on if you want per frame evaluation (use conditional filter (http://avisynth.org/ConditionalFilter)) or only when the script is opened (use the variable==6?function:last syntax (http://avisynth.org/LogicalOperators))

Atak_Snajpera
12th February 2007, 01:04
Here it is my script. I want to execute function Downmix2Stereo only when video has 6ch. Otherwise I got error message. That's why I need IF substitute.

Pookie
12th February 2007, 01:48
I found this on a site a long time ago. Perhaps it might provide some insight?



function DownMix( clip C )
{
Assert( C.AudioChannels == 6, "The Input clip MUST have 6 audio channels" )
A1=GetChannel( C, 1 )
A2=GetChannel( C, 2 )
A3=GetChannel( C, 3 )
A4=GetChannel( C, 4 )
A5=GetChannel( C, 5 )
A6=GetChannel( C, 6 )
A1=MixAudio( MixAudio( A1, A5, 0.2698, 0.2698 ), MixAudio( A3, A4, 0.1907, 0.2698 ) )
A2=MixAudio( MixAudio( A2, A6, 0.2698, 0.2698 ), MixAudio( A3, A4, 0.1907, 0.2698 ) )
A=MergeChannels( A1, A2 )
Return( C.HasVideo ? AudioDub( C, A ) : A )
}

tsp
12th February 2007, 11:16
Atak_Snajpera:You are nearly there. You just need to change the line
a_ch==6?DownMix2Stereo(ccc)
to
a_ch==6?DownMix2Stereo(ccc):last
because ? requires an "else" statement.

Atak_Snajpera
12th February 2007, 12:17
Pookie & tsp thanks for help. It's working now :-)
BTW: Why normal "IF" and "then" is not used. Instead of that they force you to use awkward command.

stickboy
13th February 2007, 07:09
Pookie & tsp thanks for help. It's working now :-)
BTW: Why normal "IF" and "then" is not used. Instead of that they force you to use awkward command.Because AviSynth uses a functional-like syntax, not imperative.

foxyshadis
13th February 2007, 12:06
Actual functional languages have nicer conditional syntax, though. (Barring the mess of XSLT.) The stripped down C++/bash pidgin could be a lot better, but at least it's not vbscript.

You can simulate a nicer syntax with lots of line breaks:

expression
\ ? filter1
\ : expression2
\ ? filter2
\ : filter3

But parentheses get mandatory with remotely complex expressions, unless you're adept at spotting expression priority problems, and pretty soon it all starts to look like lisp, and that makes people cry. :p

Having a genuine block format in 2.6 would be nice.

gzarkadas
13th February 2007, 14:42
Pookie & tsp thanks for help. It's working now :-)
BTW: Why normal "IF" and "then" is not used. Instead of that they force you to use awkward command.

If you realy want to use if...then blocks have a look at BlockStatements (http://avisynth.org/BlockStatements).