Here a quick Multi-Instance hack-up from code developed by Gavino and Martin53
Req RT_Stats, Gscript, Grunt.
Code:
Function MysteryX_MI(clip c1,clip c2,Bool "Show") {
myName="MysteryX_MI: "
Assert(RT_FunctionExist("GScriptClip"),myName+"Essential GRunT plugin installed, http://forum.doom9.org/showthread.php?t=139337")
Assert(RT_FunctionExist("GScript"),myName+"Essential GScript plugin installed, http://forum.doom9.org/showthread.php?t=147846")
Show=Default(Show,False)
Fmt = "%d ] c1AveLum=%6.2f : c2AveLum=%6.2f" # Make format string only once, not at every frame
FuncS="""
Function Fn@@@(clip c1,clip c2,Bool Show,String Fmt) {
c1
n = current_frame
If(Prev@@@ == n) { # Cache failure, requested same frame again.
RT_DebugF("%d ] Cache Failure",n,name="Fn@@@_DBUG: ")
} Else If(Prev@@@ + 1 != n) { # Init OR Rewind OR User jumped about, dont you just hate users!
if(n == 0) {
if(Prev@@@ == -666) {
RT_DebugF("%d ] Initialized to frame 0",n,name="Fn@@@_DBUG: ")
} else {
RT_DebugF("%d ] Rewind to frame 0",n,name="Fn@@@_DBUG: ")
}
} else {
RT_DebugF("%d ] User Jumped About",n,name="Fn@@@_DBUG: ")
}
}
if(Show) {
RT_Subtitle(Fmt,n, c1.RT_AverageLuma(n=n), c2.RT_AverageLuma(n=n))
}
Global Prev@@@=current_Frame # Previous frame (For next interation jump about detect)
Return Last
}
#######################################
# Unique Global Variables Initialization
#######################################
Global Prev@@@= -666 # Init vars, Prev = -666 forces initalize
#######################################
# Unique Runtime Call, GScriptClip must be a one-liner:
#######################################
ARGS = "c2,Show,Fmt"
c1.GScriptClip("Fn@@@(last, "+ARGS+")", local=true, args=ARGS)
"""
#######################################
# Unique Identifier Definition
#######################################
GIFunc ="MX" # Function Name, Supply unique name for your multi-instance function.
GIName =GIFunc+"_InstanceNumber" # Name of the Instance number Global
RT_IncrGlobal(GIName) # Increment Instance Global (init to 1 if not already exists)
GID = GIFunc + "_" + String(Eval(GIName))
InstS = RT_StrReplace(FuncS,"@@@","_"+GID)
# RT_WriteFile("DEBUG_"+GID+".TXT","%s",InstS) # UnComment to write each unique script function instance to log file
Return GScript(InstS)
}
c1=Avisource("F:\V\StarWars.avi")
c2=Avisource("F:\V\XMen2.avi")
SHOW=True
# Multi-instance with diffent args, compare results
a = MysteryX_MI(c1,c2,Show=SHOW)
b = MysteryX_MI(c1.Trim(1,0),c2.Trim(1,0),Show=SHOW)
StackVertical(a,b) # Bottom clip is 1 frame ahead of top clip (metrics) due to trim
EDIT: Small fix to debug output when user jumped about
Only a bit of testing.
EDIT: All Global Variables MUST be Assigned with preceding "Global" or will only be Local,
EDIT:
Global SomeVar =42
SomeVar = SomeVar + 1 # Local variable Somevar is assigned from Global variable SomeVar and Global variable now hidden by local
Specific to the Multi-Instance script above:
Each Global should be named and assigned like eg "Global SomeVar@@@ = 42".
EDIT: Only use above if many Global variables used. I've posted in the other thread a fix using Grunt for single instance Global.