Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th January 2012, 21:48   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Conditional Filtering Problem

Here an example from Avisynth docs,

Advanced Conditional Filtering Part II

Code:
global sep="."
global combedthreshold=25

Function IsMoving() {
        global b = (diff < 1.0) ? false : true
}

Function CombingInfo(clip c) {
        file = "interlace.log"
        global clip = c
        c = WriteFile(c, file, "a", "sep", "b")
        c = FrameEvaluate(c, "global a = IsCombed(clip, combedthreshold)")
        c = FrameEvaluate(c, "IsMoving")
        c = FrameEvaluate(c, "global diff = 0.50*YDifferenceFromPrevious(clip) + 0.25*UDifferenceFromPrevious(clip) + 0.25*VDifferenceFromPrevious(clip)")
        return c
}

v=Avisource("F.AVI")

CombingInfo(v)
The above works OK.
And here, the example following which is supposed to just get rid of the globals (EDIT: diff, a, and b).

Code:
global sep="."
global combedthreshold=25

Function IsMoving(float diff) {
        return (diff >= 1.0)
}

Function CombingInfo(clip c) {
        file = "interlace.log"

        c = WriteFile(c, file, "a", "sep", "b")
        c = FrameEvaluate(c,"
                diff = 0.50*YDifferenceFromPrevious() + 0.25*UDifferenceFromPrevious() + 0.25*VDifferenceFromPrevious()
                b = IsMoving(diff)
                a = IsCombed(combedthreshold)
        ")
        return c
}

v=Avisource("F.AVI")

CombingInfo(v)
This second example produces this:

Code:
I don't know what "a" means.I don't know what "b" means
false.false
false.false
false.false
false.false
false.false
false.false
false.false
false.false
false.false
false.false
false.false
false.true
Which is identical to the first output but with the addtional "I dont know" line.
Question is, is there a way to eradicate the "I dont know" line (EDIT: & why is it there?).

What I'm trying to do is experimental, something like this:-

Code:
Function ChooseClip(float df) {
 return df>0.5?7:df>0.25?6:df>0.125?5:df>0.0625?4:df>0.03125?3:df>0.015625?2:df>0.0078125?1:0 
}

Function MakeClopCmd(clip c,string File) {
        c = WriteFile(c, File, "Ix", """ "," """, "current_frame", append=false)
        c = FrameEvaluate(c,"
                df=YDifferenceFromPrevious()
                Ix=ChooseClip(df)
        ")
        return c
}

v=Avisource("F.AVI")

MakeClopCmd(v,"Clop.txt")
Idea of which is to choose a clip based on a conditional, in this case eg, variable Deblock_DeBlock()'s based on YDifferenceFromPrevious, via ClipClop() Filter.

Thanx in advance.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 19th January 2012 at 23:21.
StainlessS is offline   Reply With Quote
Old 20th January 2012, 01:03   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Firstly I must apologise, as it was me who added the second example.
I see now that it's not quite right. It should be:
Code:
...
Function CombingInfo(clip c) {
        file = "interlace.log"

        c = FrameEvaluate(c,"
                diff = 0.50*YDifferenceFromPrevious() + 0.25*UDifferenceFromPrevious() + 0.25*VDifferenceFromPrevious()
                b = IsMoving(diff)
                a = IsCombed(combedthreshold)
        ")
        c = WriteFile(c, file, "a", "sep", "b")
        return c
}
...
That is, the WriteFile call should come after the FrameEvaluate().
As it was, the values of a and b were not defined on the first frame (and on later frames wrongly referred to the previous frame). That's because the YDifferenceFromPrevious() requests a frame from WriteFile before the variables have been assigned a value.

The first example works OK because there the input to YDifferenceFromPrevious (etc) is the global clip, and a frame is not requested from WriteFile until all the variables have been assigned.

So your function should work if you move the WriteFile call to be after FrameEvaluate().
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 20th January 2012, 01:19   #3  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Thankyou Gavino, I hoped that this thread might attract your attention.

I guess I should have realized the reason and tried moving line order, but the conditional stuff
always gets me a little confused as to order of evaluation, its very complicated stuff eh!

Thanks again, what would we all do without you.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 20th January 2012, 01:37   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by StainlessS View Post
the conditional stuff always gets me a little confused as to order of evaluation, its very complicated stuff eh!
Yes indeed! As I said in another part of that wiki page, "Notice how the addition of run-time filters and run-time functions makes the interactions between different parts of the filter chain more complex. This added complexity is managed internally by Avisynth, so you needn't worry about it. However, care is required when setting and using variables, as the order of events can be less obvious to the script writer (you!)."

And as shodan (original author of the conditional/run-time filters) said:
Quote:
Originally Posted by sh0dan View Post
Cond. filters are quite complex - and sometimes I am even surprised of the outcome
I've corrected the example now, by the way - thanks for finding the error!
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 20th January 2012, 18:14   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
The experimental stuff mentioned above does not really work too well, YDifferenceFromPrevious
does not give a good measure of 'blockiness' (although not so bad in a small range). I am more
concerned with finding a way of using the conditionals to choose a frame from a choice of multiple clips
than with deblocking as such, BUT,

would anyone know of any plug that provides some kind of runtime quantitative measure of blockiness
of a frame?

EDIT: I'll be surprised if anybody does.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th January 2012 at 19:08.
StainlessS is offline   Reply With Quote
Reply

Tags
conditional

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:15.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.