# AVSLib :: sample script # Copyright (c) 2007 George Zarkadas (gzarkadas@users.sourceforge.net) # This program is free software; you can redistribute it and/or modify it under the terms of # the GNU General Public License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with this program; # if not, write to the "Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA" LoadModule("avslib", "array", "core") LoadModule("avslib", "array", "operators") LoadModule("avslib", "array", "slices") LoadModule("avslib", "array", "functions") # use a log file to quickly verify the correctness of looping through indices LoadModule("avslib", "debug", "logging") SetDebugFile("__log__.txt") SetDebugMode(DBG_LEVEL_1) # use DBG_NODEBUG to de-activate logging # load filter-specific modules (assumes they are at the same folder as the script) LoadPlugin("MaskTools.dll") LoadPlugin("RemoveGrain.dll") LoadPlugin("Repair.dll") Import("SeeSaw.avs") # load a reference clip global ref = AVISource("reference.avi").Trim(98, -8).Spline36Resize(480, 360) global ref_frames = ref.Framecount # in this example the filter to loop through is SeeSaw # 3*3*3*3*3*3*3 = 2187 blocks * 8 frames = 17496 frames global l1 = "2,4,6" # NRlimit global l2 = "3,5,7" # NRlimit2 global l3 = "1.3,1.5,1.7" # Sstr global l4 = "20,24,28" # SdampHi global l5 = "42,49,56" # bias global l6 = "42,49,56" # sootheT global l7 = "0,2,4" # sootheS total_loops = 7 global loop_counts = "3,3,3,3,3,3,3" Function LoopDiv(int idx, string loop_cnt) { subrange = loop_cnt.ArrayGetRange(idx) return subrange.ArrayLen > 0 ? subrange.ArrayProduct() : 1 } total_steps = loop_counts.ArrayProduct() global loop_ids = ArrayRange(1, total_loops) global loop_divs = ArrayOpFunc(loop_ids, "LoopDiv", "loop_counts") Function GetLoopIndex(int lid, int frame) { lcnt = loop_counts.ArrayGet(lid - 1) ldiv = loop_divs.ArrayGet(lid - 1) return ((frame / ref_frames) / ldiv) % lcnt # int divisions; remainder is trunced } Function GetLoopValue(int loop_id, int index) { return Eval("l" + String(loop_id) + ".ArrayGet(" + String(index) + ")") } Function ApplyFilter(int frame) { indices = ArrayOpFunc(loop_ids, "GetLoopIndex", String(frame)) values = ArrayOpArrayFunc(loop_ids, indices, "GetLoopValue") DebugLog(DBG_LEVEL_1, (frame == 0 ? "Processing frames:\n" : "") + \ "\tframe = %i\tblock = %i\tindices = %s\tvalues = %s", frame, \ (frame / ref_frames), indices, values) # In this example filter's arguments are named, so constructing the command line is # a bit more tricky cmdline = "SeeSaw(ref, NRlimit=" + values.ArrayGetString(0) + \ ", NRLimit2=" + values.ArrayGetString(1) + \ ", Sstr=" + values.ArrayGetString(2) + \ ", sdampHi=" + values.ArrayGetString(3) + \ ", bias=" + values.ArrayGetString(4) + \ ", sootheT=" + values.ArrayGetString(5) + \ ", sootheS=" + values.ArrayGetString(6) + \ ")" ret = Eval(cmdline) # run the filter; stack with the original for immediate comparison # we tream after evaluating the filter, in order for the correct frame to be returned return StackHorizontal( \ ret.Trim(frame % ref_frames, -1).SubTitle(cmdline, size=12, \ text_color=color_white, halo_color=color_gray20), \ ref.Trim(frame % ref_frames, -1).SubTitle("Original", size=12, \ text_color=color_white, halo_color=color_gray20)) } DebugLog(DBG_LEVEL_1, "Starting filter looping\n\tloop_ids = %s\n\tloop_divs = %s", \ loop_ids, loop_divs) # in order for stackhorizontal to work, must stack here also clp = ref.Loop(total_steps) return ScriptClip(StackHorizontal(clp, clp), "ApplyFilter(current_frame)")