Log in

View Full Version : conditionalreader help?


vinujan
30th April 2010, 21:21
i'm trying to apply different strengths to a range of frames, i've got grey borders on the left and right side of the picture.

By using tweak(cont=), i've made them unnoticeable but there are certain frames where i have to change the strength of tweak(cont=)

script
a=ffmpegsource2("c:\tbd.mkv")

global r_tweak_cont = 2.2
global l_tweak_cont = 2.0

c1=crop(a,1918,0,0,0).tweak(cont=r_tweak_cont).conditionalreader("c:\right_cont.txt","r_tweak_cont").converttorgb24().crop(1,0,0,0)

e1=overlay(a,c1,x=1919)

g1=crop(e1,0,0,2,0).tweak(cont=l_tweak_cont).conditionalreader("c:\left_cont.txt","l_tweak_cont").converttorgb24().crop(0,0,1,0)

overlay(e1,g1)

Spline36Resize(1280,720)

right_cont.txt

type float
default 2.2
r 5141 5278 2.0
r 18205 18248 2.8

left_cont.txt

type float
default 2.0
r 18205 18248 2.6

the script only returns a clip using global r_tweak_cont and l_tweak_cont values, and not conditionalreader values.

can anyone help? i think i'm using conditionalreader incorrectly

:thanks:

Gavino
30th April 2010, 22:52
You have to put the Tweaks inside ScriptClip calls in order for them to use the 'run-time' values of the variables.
a=ffmpegsource2("c:\tbd.mkv")
c1=crop(a,1918,0,0,0).ScriptClip("tweak(cont=r_tweak_cont)").conditionalreader("c:\right_cont.txt","r_tweak_cont").converttorgb24().crop(1,0,0,0)

e1=overlay(a,c1,x=1919)

g1=crop(e1,0,0,2,0).ScriptClip("tweak(cont=l_tweak_cont)").conditionalreader("c:\left_cont.txt","l_tweak_cont").converttorgb24().crop(0,0,1,0)

overlay(e1,g1)

Spline36Resize(1280,720)
No need to make the variables global (or even initialise them in the script).

vinujan
1st May 2010, 00:16
thank you very much Gavino :D

birdinred
1st October 2011, 18:16
"...put the Tweaks inside ScriptClip calls in order for them to use the 'run-time' values of the variables."

oh yeah,so great.

IanB
2nd October 2011, 01:31
The functionality above is another example for the concept "Script the Decision not the Function".

ScriptClip() works by compiling it's argument string for each and every frame. This results in building a filter chain, executing it for the current frame and tearing it down, for each and every frame.

Tweak() like a lot of other filters trade extra processing on creation for reduced processing per frame. Fortunately both creation and execution for Tweak() are pretty quick.

And the Avisynth compiler is not at all optimised. We take the view if it take 1/10th second to compile the script or 10 seconds to compile the script it is not that important, particularly if we can do 1000 frames per second by spending those 10 seconds at startup. Most optimising effort goes into the GetFrame code, far less into the Constructor code.

By using ConditionalFilter() we can select between the result of 2 static filter chains. Only the selected chain is executed for the current frame.

So if Tweak() were not so forgiving on creation, a partial solution could be :-...
T20 = tweak(cont=2.0) # Static 2.0 chain
T26 = tweak(cont=2.6) # Static 2.6 chain
Tcond=ConditionalFilter(T20, T26, "l_tweak_cont", "=", "True").ConditionalReader("c:\left_cont.txt","l_tweak_cont") # Runtime decision
...left_cont.txttype bool
default false
r 18205 18248 true
For the original problem the solution quoted is adequate. If the l_tweak_cont values were far more variable per frame the solution quoted is actually preferable. It is just worth keeping in mind "Script the Decision not the Function" when approaching this type of problem.

Some filters like the resizers have considerable startup overhead, they actually compile custom MMX/SSE code for the current resizer.