PDA

View Full Version : @sh0dan : WHILE function in Avisynth ?


bilu
8th March 2003, 14:41
Hi Sh0dan,

I haven't found yet any sort of conditional WHILE function on Avisynth.

I would like to change applied functions based on a variable, used as a flag.

Anything I can use? A workaround maybe?

Best regards,
Bilu

sh0dan
8th March 2003, 15:38
"While" suggests some kind of loop, which isn't possible.

There is a feature request present at sourceforge, but I don't think any work has been done on it. I personally have no idea how to rewrite the script parser, since I havn't got the skills.

bilu
8th March 2003, 16:23
Sh0dan,

As a workaround, and having Ddogg's ideas and mine on CALL command (http://forum.doom9.org/showthread.php?s=&threadid=46506&pagenumber=2) as a subject, do you know any way to somehow discard imported scripts?

Worth looking, related to this thread also:

http://forum.doom9.org/showthread.php?threadid=47377

Best regards,
Bilu

sh0dan
8th March 2003, 17:53
You are really unclear on your question. I'm thinking of C-style while loops. I don't know what you are thinking of.

The feature request (http://sourceforge.net/tracker/index.php?func=detail&aid=611945&group_id=57023&atid=482676) I mentioned.

bilu
8th March 2003, 20:13
Humm... I've seen Richard Berg's answer on you feature request, so this question is answered by now.

Sorry for not being clear. I was talking about the same concept you posted in this thread. (http://forum.doom9.org/showthread.php?s=&threadid=48027)

But I hadn't read that thread before, and since Nic's CALL filter implements some sort of scheduling, me and Ddogg were thinking about applying this to internal filters, but only within specific intervals specified by events ( being it a frame range or a variable change).

I'm not a programmer and don't have a clue on how hard it can be to apply filtering only while a variable meets the required conditions. :confused:

Bilu

sh0dan
9th March 2003, 18:21
The problem is, that the script is interpreted at load, and isn't used, when the filter graph is created, and the application begins to request frames.

Therefore conditions within the script-system cannot be checked when the filter is running, because the script is in iself no longer active - only the filter graph that was created from it.

bilu
9th March 2003, 18:39
Humm, I see. So, if my interpretation is correct, it would need to be done by a filter, since it would then be part of the filter graph.

A filter could check variables the same way it checks the framecount? (filters can check the framecount, right? Is it what CALL does?)

If it's possible maybe Nic could convert CALL into some kind of event-based scheduler :)

Or maybe i'm smoking something bad eheh :D

Bilu

sh0dan
9th March 2003, 18:52
Yes - filter solution is the way to go!

Bidoche
10th March 2003, 15:00
While and other flow control fonctions will probably be included in the 3.0 parser.

DDogg
11th March 2003, 04:02
Bidoche, great news! Won't that require really tearing into the guts of Avisynth? I had got the impression this was a place that terrified you guys :-)

ErMaC
11th March 2003, 10:36
Not Bidoche - danger is his middle name.

I look forward to a more robust scripting engine as well, as I outlined in a post on the AVS developer board (which is now closed, I hear).

vion11
11th March 2003, 12:14
some kind of loops can programmed by using recursive functions.

Bidoche
11th March 2003, 12:50
Well, it's more the enormity of the task that terrifies me than its difficulty.
I already thought how to make such a parser, but in an early attempt,
it took me nearly a full week to do an 'arithmetic and boolean only' parser.
I let you imagine for the whole....

@DDogg

in 3.0 much of avisynth guts will be torn apart anyway.

bilu
11th March 2003, 13:08
Originally posted by sh0dan
The problem is, that the script is interpreted at load, and isn't used, when the filter graph is created, and the application begins to request frames.

Therefore conditions within the script-system cannot be checked when the filter is running, because the script is in iself no longer active - only the filter graph that was created from it.

@bidoche
If Avisynth behaves just as a parser that creates a filter graph, wouldn't it be better done with a filter?

I'm not a programmer, but I already looked at Ben's docs (http://www.avisynth.org/index.php?page=BensAviSynthDocs) and it seems to me that a filter that could check variables and behave as a parent filter using this functionality:


virtual AVSValue Invoke(const char* name, const AVSValue args, const char** arg_names=0);

You can use this to call a script function. There are many script functions which can be useful from other filters; for example, the Bob filter uses SeparateFields, and several source filters use UnalignedSplice. Some functions, like Weave, are implemented entirely in terms of other functions.

If you're calling a function taking exactly one argument, you can simply pass it in the args parameter; Invoke will convert it into an array for you. In order to call a function taking multiple arguments, you will need to create the array yourself; it can be done like this:

AVSValue args[5] = { clip, 0, true, 4.7, "my hovercraft is full of eels" };
env->Invoke("Frob", AVSValue(args, 5));

In this case Frob would need to have a parameter-type string like "cibfs" or "cfbfs" or "cf.*".

The arg_names parameter can be used to specify named arguments. Named arguments can also be given positionally, if you prefer.

Invoke throws IScriptEnvironment::NotFound if it can't find a matching function prototype. You should be prepared to catch this unless you know that the function exists and will accept the given arguments.

typedef void (__cdecl *ShutdownFunc)(void* user_data, IScriptEnvironment* env);
virtual void AtExit(ShutdownFunc function, void* user_data);

If you find yourself wanting an AvisynthPluginShutdown export, this is the way to get that effect. Functions added through AtExit are called (in the opposite order that they were added) when the corresponding ScriptEnvironment goes away.


Probably messing with Avisynth core and creating a WHILE syntax would mean parsing to a filter-type component (seems something new in Avisynth, since we would use script language that would be parsed and not a filter by itself - a sort of "transforming language into filter parameters", which is different from parsing filters into a filter graph.

Best regards,
Bilu

ErMaC
11th March 2003, 13:17
I think While loops can behave both in filter space and core space, to put it one way. For a loop that reacts to the analysis of a frame, I think it would exist in filter space. But say you have a function like:

source=avisource(blah.avi)
While(framecount<30000) (last + souce)

if you wanted to loop the same blah.avi over and over again until you hit 30000 frames. This doesn't really involve any sort of activities traditionally thought as "filters" (although technically AVIsource is a source filter).

Bidoche
11th March 2003, 13:31
It will be done with special objects, something like this :

class Statement {
public:
virtual void execute() {}
virtual ~Statement() {}
};

The parser create (compile to) a graph of those statements (of the many subclasses) and execute it.
When done, it gets the return value as the "last" entry in the vartable or from a ReturnException that may be thrown.

bilu
11th March 2003, 13:34
@ErMaC

I posted this example in another thread, posted here again just to show some functionality we can get now:

First example:

INFO.BAT
=========
del c:\info.avs
for /F "usebackq" %%i IN (`time /t`) DO @echo Time="%%i" >> c:\info.avs
for /F "usebackq" %%i IN (`date /t`) DO @echo Date="%%i" >> c:\info.avs

In AVS script
==============
CALL(BlankClip,"c:\info.bat","-2")
Import("c:\info.avs")


Second example

Autocrop(mode=2,wMultOf=16,hMultOf=16,threshold=40)
Call("cmd /c copy D:\autocrop.log D:\crop.avs","-2")
import("D:\avs_filters\avs25\tests\analyse\crop.avs")



Imagine you would want to use CALL (or other filter, or maybe Avisynth itself in the future) to get a variable value from the outside with a certain frequency, and then change the filters used based on a value change on that variable.

It would be a sort of flag that comes from the outside, i.e. doesn't depend on Avisynth. In this case a script cannot be totally parsed to a filter graph: some sort of monitoring would need to be there, and at the moment it can only be done by a filter.

Links of interest:

CALL command (http://forum.doom9.org/showthread.php?s=&threadid=46506&pagenumber=2)

Syntax Q - filter args as a variable (http://forum.doom9.org/showthread.php?s=&threadid=47972&pagenumber=2)

Conditional Filter equivalent syntax in avs 2.5? (http://forum.doom9.org/showthread.php?s=&threadid=48027)

Time incrementer (http://forum.doom9.org/showthread.php?s=&threadid=47377)

Best regards,
Bilu

bilu
11th March 2003, 16:13
Since I'm not a programmer, I would like someone to confirm if I'm right and share some ideas. Please? :D

Bilu