Log in

View Full Version : I find avisynth scripting difficult to learn


lisztfr9
3rd June 2014, 15:16
I'm not smart also. What makes it difficult is in regards of the notion of object, i think all computer languages are more or less object-oriented. In Qbasic we have simple objects, in Html, css code is defining versatile objects, more like subroutines...

In Avisinth, i call Function, ConditionalFilter, Scriptclip, last(), as object (ConditionalReader operates on variables, so it's another class of objects). The countenance is not free, they are predefined forms.

In Qbasic, user defined Types of variables are objects.

In Avisynth, what's the main difference between ConditionalFilter and Scripclip ? That is, the first one takes 2 clips as argument, the second only one. But since all theses entities can call each other, in what situation rather use this or that and the main purpose of each one never remains clear to me. A Function returns a Clip, but can embed ConditionalReader which takes 2... FrameEvaluate is the same as Scriptclip but doesn't return a clip. With Grunt, all variables can be passed to scriptclip, so is FrameEvaluate still useful ? FrameEvaluate can be replace by the expression with variable current_frame, right ?

Gscript simplifies the way to write expressions. For calculating the average Luma for 4 frames, i could write an FOR loop like (pseudo code)
For delta = -2 to 2
Ave : Ave + AverageLuma(Delta)
...
Mean = Ave / 5

Or not use Gscript. Because the "old" code is not depreciated, so 2 kinds of syntax coexist.

In Qbasic, a function is called, the variable it computes is returned to the call location. In Avisynth a Function can contain anything, it's ubiquitous, there is no clear hierarchy of programming structures... except an "hydraulic" notion of flow, which must be respected. In qbasic a Function is declared and put later prgrm at a special place. Here a function is written anywhere before it is called.

What we most want is applying filters dynamically, and better for a delta of 2 frames for more security. At Frame n, some easy StDeviation routines should be available a bit like "snipped" in qbasic. Qbasic peoples used to share their code, even snipped, useful routines. My two cents,

L

PS, More difficulties arrive with the huge complexity of image treatment algorithm, choosing the appropriates filter and checking the result visually. In python etc, it's only right or wrong. Here, subjectivity is involved.

colours
3rd June 2014, 18:24
Those are two rather huge cents you have there.

The notion of "flow" is because Avisynth is primarily a graph (https://en.wikipedia.org/wiki/Filter_graph) description language, not a programming language. It just happens to have some conveniences that make it look like one. The inbuilt runtime filters blur the distinction a bit, but the use of those runtime filters is discouraged in any not-entirely-basic script as Avisynth's cache management is somewhat fragile. Which, again, is because Avisynth is not a programming language!

(You could theoretically use Avisynth scripting as a programming environment, but that's kind of like saying programming in Malbolge is possible.)

ConditionalFilter is for choosing between two clips based on a condition, while ScriptClip creates a new clip for every frame as specified. In a sense ScriptClip is much more flexible, though you're restricted to having the same clip properties as the original clip.

It kind of seems like what you want is already well covered by ScriptClip or GScript. If you need something more fancy (or if runtime filtering is too slow), you can always write your own filter, where you can basically do whatever you want to the frames.

The construction of the filter graph is as black-and-white as interpreting Python is (except with nondeterministic filters); the only subjectivity lies in what filters you decide to use. It's not an inherent property of the Avisynth framework, but an inherent property of video processing. If you wanted to write video filters in Python you'd be faced with exactly the same subjectivity. (Note: this is strongly not recommended because Python is lolslow.)

foxyshadis
3rd June 2014, 23:26
If you want procedural programming, or examining individual pixels, write a filter or chain a series of filters that do what you want. Avisynth is not matlab, it's purpose-built for lightweight chaining a series of filters together. It's also based on functional programming, which anyone from a Haskell background will immediately understand. The reason FrameEvaluate, ConditionalFilter, and ScriptClip are so badly designed and painful to use is that Avisynth just doesn't work that way -- at best they're for early filter prototyping, before writing the C version. Most people who use Avisynth will never need to use them.

The problem with forcing Avisynth to be procedural is that functional Avisynth is designed to only process frames you request. It's enormously wasteful to deinterlace every single field when you only use half of them, for instance.

I don't understand your assertion that Avisynth functions can be anything, though. They take some values and they return a value; that's basically the definition of functions in any language. Just because Avisynth has a special VideoClip object that's often passed around doesn't change that.

lisztfr9
5th June 2014, 13:31
Thanks for your interesting replies. A good practice hopefully, i will try, is to name every clip i create with a function "name", or "label" (Clip, <name>, row).