The script execution model/The filter graph

From Avisynth wiki
Revision as of 20:07, 15 September 2015 by Raffriff42 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The final purpose of every AviSynth script is to create a filter graph that can be used by the top-level AVI stream object (see previous section) to call the filters needed for the creation of each specific frame that is requested by the host video application.

This filter graph is implicit in the sense that it is not directly available to script writers for querying or modification. However it is created and built-up on each filter call that the script source code makes, using the following rules:

  • Each filter -actually its resulting clip- links to all its source clips (those that it uses directly or indirectly for input).
  • Source filters (such as AviSource) do not link to other clips. Their resulting clip is a leaf-node in the filter graph.
  • Only filters -ie their resulting clips- that are linked by the final clip returned by the script are part of the filter graph. That is a clip is part of the filter graph only if there is a path that connects it with the final clip returned by the script.
  • User-defined script functions do not appear (as such) in the filter graph. A function call generates a filter graph corresponding to the evaluation of the function body with its arguments set to the values passed in the call. (Consequently, there is no run-time overhead in calling a function - the same filter graph will be generated as if the function body had been written 'in-line'.)

An example of a filter graph

Consider the following script, which loads a clip, makes a simple levels processing and muxes it with a custom sound track; then it overlays on top of it another clip, along with its inverted image, as separate windows.

Levels(10, 1, 248, 0, 255)
aud = WavSource("mysoundtrack.wav")
AudioDub(last, aud)
ov = AviSource("clip2.avi")
ov1 = Lanczos4Resize(ov, 280, 210)
ov2 = ov1.Invert()
w = last.Width
h = last.Height
Overlay(ov1, x=w-280-40, y=40) # first clip is last
Overlay(ov2, x=w-280-40, y=h-210-40)

The filter graph that results from the script code above is the following.

AviSource(clip1) <-- Levels <--+
WavSource <--------------------+-- AudioDub <--+
AviSource(clip2) <-- Lanczos4Resize <--+-------+-- Overlay <--+          
                                       |                      |
                                       +-- Invert <-----------+-- Overlay (filter graph's root)

The root of the filter graph, that is the filter from which the host video application requests video frames is the second Overlay (the last line of the script).

Back to the script execution model.

Personal tools