GRunT

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(GRunT)
 
m (add links, use Template:FuncDef, Template:BoxWidthIndent more TODO)
Line 19: Line 19:
 
* Run-time functions can be called from a user function
 
* Run-time functions can be called from a user function
 
* Run-time functions can be applied to any frame (relative to the current one)
 
* Run-time functions can be applied to any frame (relative to the current one)
* Additional variant of ConditionalFilter with single boolean expression
+
* Additional variant of [[ConditionalFilter]] with single boolean expression
* Fixes a fairly serious bug in the run-time system
+
* Fixes a fairly serious [http://forum.doom9.org/showthread.php?t=138755 bug] in the run-time system
* Lightweight plugin extending the standard run-time environment, minimal time and memory overhead
+
* Lightweight plugin extending the standard run-time environment with minimal time and memory overhead
 
* 100% backwards compatible with existing scripts
 
* 100% backwards compatible with existing scripts
  
GRunT should be useful to anyone who uses the run-time filters, from those who make occasional use of ScriptClip to those who write complex functions based on run-time features (such as Restore24 or MRestore).
+
'''GRunT''' should be useful to anyone who uses the run-time filters, from those who make occasional use of [[ScriptClip]] to those who write complex functions based on run-time features (such as Restore24 or MRestore).
 
<br>
 
<br>
 
<br>
 
<br>
== [[Script variables|Syntax and Parameters]] ==
+
== Syntax and Parameters ==
  
  
Line 33: Line 33:
 
The plugin provides extended versions of the following run-time filters:
 
The plugin provides extended versions of the following run-time filters:
 
* [[ScriptClip#ScriptClip|ScriptClip]]
 
* [[ScriptClip#ScriptClip|ScriptClip]]
:<code>ScriptClip(clip, string, bool "showx", bool "after_frame", string "args", bool "local")</code>
+
:{{FuncDef|ScriptClip(clip, string, bool "showx", bool "after_frame", string "args", bool "local")}}
:<code>GScriptClip(clip, string, bool "show", bool "after_frame", string "args", bool "local")</code>
+
:{{FuncDef|GScriptClip(clip, string, bool "show", bool "after_frame", string "args", bool "local")}}
 
* [[FrameEvaluate#FrameEvaluate|FrameEvaluate]]
 
* [[FrameEvaluate#FrameEvaluate|FrameEvaluate]]
:<code>FrameEvaluate(clip, string, bool "showx", bool "after_frame", string "args", bool "local")</code>
+
:{{FuncDef|FrameEvaluate(clip, string, bool "showx", bool "after_frame", string "args", bool "local")}}
:<code>GFrameEvaluate(clip, string, bool "show", bool "after_frame", string "args", bool "local")</code>
+
:{{FuncDef|GFrameEvaluate(clip, string, bool "show", bool "after_frame", string "args", bool "local")}}
 
* [[ConditionalFilter]]
 
* [[ConditionalFilter]]
:<code>ConditionalFilter(clip, clip, clip, string, bool "showx", string "args", bool "local")</code>
+
:{{FuncDef|ConditionalFilter(clip, clip, clip, string, bool "showx", string "args", bool "local")}}
:<code>ConditionalFilter(clip, clip, clip, string, string, string, bool "showx", string "args", bool "local")</code>
+
:{{FuncDef|ConditionalFilter(clip, clip, clip, string, string, string, bool "showx", string "args", bool "local")}}
:<code>GConditionalFilter(clip, clip, clip, string, bool "show", string "args", bool "local")</code>
+
:{{Template:FuncDef|GConditionalFilter(clip, clip, clip, string, bool "show", string "args", bool "local")}}
:<code>GConditionalFilter(clip, clip, clip, string, string, string, bool "show", string "args", bool "local")</code>
+
:{{FuncDef|GConditionalFilter(clip, clip, clip, string, string, string, bool "show", string "args", bool "local")}}
 
* [[WriteFile]]
 
* [[WriteFile]]
:<code>WriteFile(clip, string "filenamex", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")</code>
+
:{{FuncDef|WriteFile(clip, string "filenamex", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")}}
:<code>GWriteFile(clip, string "filename", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")</code>
+
:{{FuncDef|GWriteFile(clip, string "filename", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")}}
 
* [[WriteFileIf]]
 
* [[WriteFileIf]]
:<code>WriteFileIf(clip, string "filenamex", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")</code>
+
:{{FuncDef|WriteFileIf(clip, string "filenamex", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")}}
:<code>GWriteFileIf(clip, string "filename", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")</code>
+
:{{FuncDef|GWriteFileIf(clip, string "filename", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")}}
  
 +
The alternative ({{FuncDef|G*}}) names <!-- {{FuncDef|GScriptClip, GFrameEvaluate, GConditionalFilter, GWriteFile}} and {{FuncDef|GWriteFileIf}} -->may also be used. However, if running on AviSynth version 2.57 or earlier, then the alternative names '''must''' be used.<br>
 +
(This restriction is necessary for technical reasons - sorry about that.)
  
The alternative names <code>GScriptClip, GFrameEvaluate, GConditionalFilter, GWriteFile</code> and <code>GWriteFileIf</code> may also be used. However, if running on version '''2.57 or earlier''' of AviSynth, then '''only''' the alternative names may be used.<br>(This restriction is necessary for technical reasons - sorry about that.)
 
  
 
Each filter is 100% backwards compatible with its standard equivalent, but has two additional optional arguments:
 
Each filter is 100% backwards compatible with its standard equivalent, but has two additional optional arguments:
  
:*<code>string args</code>: the variables whose values are to be imported into the run-time script, written as a list of names separated by commas. The given variable names are evaluated in the current (compile-time) context, so can include function parameters or local variables. Each value becomes the initial value of the corresponding variable at each invocation of the run-time script.
+
:*''string'' {{FuncDef|args}}: the variables whose values are to be imported into the run-time script, written as a list of names separated by commas. The given variable names are evaluated in the current (compile-time) context, so can include function parameters or local variables. Each value becomes the initial value of the corresponding variable at each invocation of the run-time script.
:*<code>bool local</code>: if true, the filter will evaluate its run-time script in a new variable scope, avoiding unintended sharing of variables between run-time scripts. Default is true if args is also specified, otherwise false (to preserve backwards compatibility).
+
:*''bool'' {{FuncDef|local}}: if true, the filter will evaluate its run-time script in a new variable scope, avoiding unintended sharing of variables between run-time scripts. Default is true if args is also specified, otherwise false (to preserve backwards compatibility).
 +
 
  
 
A short example (based on the original) shows how this greatly simplifies passing function parameters into a run-time script.
 
A short example (based on the original) shows how this greatly simplifies passing function parameters into a run-time script.
<pre>function bracket_luma(clip c, float th1, float th2) {
+
<div {{BoxWidthIndent|60|2}}>
  Assert(0 <= th1 && th1 < th2 && th2 <= 255, "Invalid thresholds!")
+
function bracket_luma(clip c, float th1, float th2) {
  ScriptClip(c, """
+
    Assert(0 <= th1 && th1 < th2 && th2 <= 255, "Invalid thresholds!")
    avl = AverageLuma()
+
    ScriptClip(c, """
    avl <= th1 ? last.BlankClip() : avl >= th2 ? last.BlankClip(color=color_white) : last
+
      avl = AverageLuma()
  """, args="th1,th2", local=true)
+
      avl <= th1 ? last.BlankClip() : avl >= th2 ? last.BlankClip(color=color_white) : last
}</pre>
+
    """, args="th1,th2", local=true)
 +
}
 +
</div>
 
This is much easier than the standard approach of dynamically building the runtime script using string concatenation, or passing the values via global variables.
 
This is much easier than the standard approach of dynamically building the runtime script using string concatenation, or passing the values via global variables.
  
 
And because the run-time script is evaluated in its own scope, there is now no problem in calling bracket_luma more than once in the same script (previously the variables th1 and th2 of different instances could interfere with each other).  
 
And because the run-time script is evaluated in its own scope, there is now no problem in calling bracket_luma more than once in the same script (previously the variables th1 and th2 of different instances could interfere with each other).  
 +
  
 
Elements of the <code>args string</code> can also take the form <tt>'name=expression'</tt> - the expression is evaluated in the current context and is used to set the value of the named variable in the run-time script.<br>
 
Elements of the <code>args string</code> can also take the form <tt>'name=expression'</tt> - the expression is evaluated in the current context and is used to set the value of the named variable in the run-time script.<br>

Revision as of 16:38, 4 January 2016

Abstract
Author Gavino
Version v1.0.1
Download GRunT101.zip
Category Support filters
License GPLv2
Discussion Doom9 Thread


Contents

Description

AviSynth's run-time environment is very powerful, supporting complex video processing that would be difficult or impossible to perform in a normal script. But it's not easy to use - the behaviour of run-time scripts (especially in combination) can be hard to understand and there are usability problems concerning scope and lifetime of variables.

GRunT (Gavino's Run-Time ) is a plugin which addresses these and other problems, making the run-time system much easier to use.

Features

  • Simple, natural and robust way to pass variables into a run-time script from 'outside'
  • A run-time script can be evaluated in its own independent scope
  • Run-time functions can be called from a user function
  • Run-time functions can be applied to any frame (relative to the current one)
  • Additional variant of ConditionalFilter with single boolean expression
  • Fixes a fairly serious bug in the run-time system
  • Lightweight plugin extending the standard run-time environment with minimal time and memory overhead
  • 100% backwards compatible with existing scripts

GRunT should be useful to anyone who uses the run-time filters, from those who make occasional use of ScriptClip to those who write complex functions based on run-time features (such as Restore24 or MRestore).

Syntax and Parameters

Run-Time filters:

The plugin provides extended versions of the following run-time filters:

ScriptClip(clip, string, bool "showx", bool "after_frame", string "args", bool "local")
GScriptClip(clip, string, bool "show", bool "after_frame", string "args", bool "local")
FrameEvaluate(clip, string, bool "showx", bool "after_frame", string "args", bool "local")
GFrameEvaluate(clip, string, bool "show", bool "after_frame", string "args", bool "local")
ConditionalFilter(clip, clip, clip, string, bool "showx", string "args", bool "local")
ConditionalFilter(clip, clip, clip, string, string, string, bool "showx", string "args", bool "local")
GConditionalFilter(clip, clip, clip, string, bool "show", string "args", bool "local")
GConditionalFilter(clip, clip, clip, string, string, string, bool "show", string "args", bool "local")
WriteFile(clip, string "filenamex", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")
GWriteFile(clip, string "filename", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")
WriteFileIf(clip, string "filenamex", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")
GWriteFileIf(clip, string "filename", string, ..., string, ..., bool "append", bool "flush", string "args", bool "local")

The alternative (G*) names may also be used. However, if running on AviSynth version 2.57 or earlier, then the alternative names must be used.
(This restriction is necessary for technical reasons - sorry about that.)


Each filter is 100% backwards compatible with its standard equivalent, but has two additional optional arguments:

  • string args: the variables whose values are to be imported into the run-time script, written as a list of names separated by commas. The given variable names are evaluated in the current (compile-time) context, so can include function parameters or local variables. Each value becomes the initial value of the corresponding variable at each invocation of the run-time script.
  • bool local: if true, the filter will evaluate its run-time script in a new variable scope, avoiding unintended sharing of variables between run-time scripts. Default is true if args is also specified, otherwise false (to preserve backwards compatibility).


A short example (based on the original) shows how this greatly simplifies passing function parameters into a run-time script.

function bracket_luma(clip c, float th1, float th2) {
   Assert(0 <= th1 && th1 < th2 && th2 <= 255, "Invalid thresholds!")
   ScriptClip(c, """
     avl = AverageLuma()
     avl <= th1 ? last.BlankClip() : avl >= th2 ? last.BlankClip(color=color_white) : last
   """, args="th1,th2", local=true)
}

This is much easier than the standard approach of dynamically building the runtime script using string concatenation, or passing the values via global variables.

And because the run-time script is evaluated in its own scope, there is now no problem in calling bracket_luma more than once in the same script (previously the variables th1 and th2 of different instances could interfere with each other).


Elements of the args string can also take the form 'name=expression' - the expression is evaluated in the current context and is used to set the value of the named variable in the run-time script.
Example: args="x, y=n+1, c=c.Trim(2, 0)" will provide values for the variables x, y and c.
Here y need not even exist in the current environment (although x, n and c must).


Examples

TO DO

Changelog

v1.0.1 (Gavino, 27th September 2008):
- fix for Avisynth 2.5.7 (have to use alternative names for filters, eg GScriptClip)

v1.0.0 (Gavino, 9th July 2008):
- add 'args' and 'local' to filters
- run-time functions with offset from current_frame
- new variant of ConditionalFilter (single boolean expr)

v0.1 (Gavino, 18th June 2008):
- fix Avisynth bug in setting of current_frame
- make current_frame global (allows run-time functions to be cslled inside user functions)


Archived Downloads

Version Download Mirror
v1.0.1 GRunT101.zip


External Links




Back to External Filters

Personal tools