# 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 a reference frame clip global ref = AVISource("reference.avi").Trim(150, -1) # in this example the filter to loop through is Levels # 4*3*4*3*3 = 432 frames global l1 = "0,40,80,120" # input_low global l2 = "0.75,1.0,1.5" # gamma global l3 = "255,210,165,120" # input_high global l4 = "0,80,160" # output_low global l5 = "255,190,120" # output_high total_loops = 5 global loop_counts = "4,3,4,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 / ldiv) % lcnt } 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\tindices = %s\tvalues = %s", frame, indices, values) # In this example all filter's arguments are contained in 'values' array, so constructing # the command line is particularly easy; if named arguments are wanted, use StrPrint() or # ArrayGetString() ret = Eval("ref.Levels(" + values + ")") return ret.SubTitle(values) } DebugLog(DBG_LEVEL_1, "Starting filter looping\n\tloop_ids = %s\n\tloop_divs = %s", \ loop_ids, loop_divs) return ScriptClip(ref.Loop(total_steps), "ApplyFilter(current_frame)")