Log in

View Full Version : Deshaker script


goorawin
2nd February 2015, 03:42
Is there any way to write the two passes required by deshaker into the one Avisynth script ?
It would require completing the first pass before starting the second.

I do use Deshaker in Virtual Dub now and it works well. I have automated the process of colour correction, clip enhancing, noise reduction and stabilization through Virtual Dub. So I can set up a batch to do as many clips as required and let the computer do all the work unattended. I have done thousands of clips this way very successfully. Interestingly I have found that less than 5% need to be manually corrected, which is very easy to do anyway.


However I would like to do the stabilization before any other image processing. Through the testing I have done there appears to be a slight improvement in both image quality and processing speed when I do this.

So my question is, is it possible to write such a script, if so how?

Script 1 - Working:
SetMemoryMax(256)
SetMTMode(5,6)
Clip="G:\Europe 2014\Video\Raw\Part02 Final\00293.MTS"
V1=avss_26_DSS2(Clip, fps = 50)
A1=FFAudioSource(Clip,track = -1)
AudioDub(V1, A1)
SetMTMode(2,0)
a = frfun7(lambda=1.80, T=2.3, Tuv=2.0, P=0)
b = a.frfun7()
SeeSaw(a, b)
SetMTMode(1,0)
Autoadjust(auto_gain= true, input_tv=false, dark_limit= 1.10, dark_exclude=0.95, bright_limit=5.00, bright_exclude=0.00001, gain_mode= 0, auto_balance=true, chroma_process=0, balance_str=0.45, output_tv=true, high_quality=True, high_bitdepth=False, debug_view=false)
Smoothlevels(input_low=0,gamma=1.01,input_high=230,output_low=0,output_high=255, chroma=100,limiter= 2,Lmode= 3, darkSTR=80,brightSTR=90,Ecurve= 1,Ecenter=155,protect=16,dither=50,useMT=4,useOPT= 1)
SmoothTweak(Saturation=1.20,hue1=1,hue2=1)

Script 2 - Avisynth deshaker Pass 1 Working
LoadVirtualDubPlugin ("C:\Virtual Dub\plugins32\Deshaker.vdf", "deshaker", preroll=0)
Clip=("G:\Europe 2014\Video\Raw\Part01 Raw\00134.MTS")
V1=avss_26_DSS2(Clip, fps = 50)
A1=FFAudioSource(Clip,track = -1)
AudioDub(V1, A1).ConvertToRGB32(matrix="PC.709").AdvancedMultiTrim("0,-50")
Deshaker("19|1|30|4|1|0|1|0|640|480|1|2|1000|1000|1000|1000|4|1|3|2|8|30|300|4|C:\\Users\\Peter\\AppData\\Local\\Deshaker\\Deshaker.log|0|0|0|0|0|0|0|0|0|0|0|0|0|1|10|10|5|10|0|0|30|30|0|0|1|0|1|1|0|10|1000|1|90|1|1|20|5000|100|20|1|0|ff00ff")

Script 3 - Avisynth deshaker Pass 2 Working
SetMemoryMax(500)
SetMTMode(3,4)
LoadVirtualDubPlugin ("C:\Virtual Dub\plugins32\Deshaker.vdf", "deshaker", preroll=0)
Clip=("G:\Europe 2014\Video\Raw\Part02 Final Raw\00301.MTS")
V1=avss_26_DSS2(Clip, fps = 50)
A1=FFAudioSource(Clip,track = -1)
AudioDub(V1, A1)
AdvancedMultiTrim("0,-100")
SetMTMode(2,0)
ConvertToRGB32()
Deshaker("19|2|30|4|1|0|1|0|640|480|1|2|1000|1000|1000|1000|4|1|3|2|8|30|300|4|C:\\Users\\Peter\\AppData\\Local\\Deshaker\\Deshaker.log|0|0|0|0|0|0|0|0|0|0|0|0|0|1|10|10|5|10|0|0|30|30|0|0|1|0|1|1|0|10|1000|1|90|1|1|20|5000|100|20|1|0|ff00ff")
ConvertToYV12()

Script 4 to be added to the end of script 3

SetMTMode(2,0)
a = frfun7(lambda=1.80, T=2.3, Tuv=2.0, P=0)
b = a.frfun7()
SeeSaw(a, b)
SetMTMode(1,0)
Autoadjust(auto_gain= true, input_tv=false, dark_limit= 1.10, dark_exclude=0.95, bright_limit=5.00, bright_exclude=0.00001, gain_mode= 0, auto_balance=true, chroma_process=0, balance_str=0.45, output_tv=true, high_quality=True, high_bitdepth=False, debug_view=false)
Smoothlevels(input_low=0,gamma=1.01,input_high=230,output_low=0,output_high=255, chroma=100,limiter= 2,Lmode= 3, darkSTR=80,brightSTR=90,Ecurve= 1,Ecenter=155,protect=16,dither=50,useMT=4,useOPT= 1)
SmoothTweak(Saturation=1.20,hue1=1,hue2=1)


How to combine scripts 2, 3 and 4 into one working script????????

StainlessS
2nd February 2015, 06:43
Just something to give you the idea.


avisource("test.avi").trim(1000,-500) # 500 Frames
NAME="Test.txt"

RT_FileDelete(NAME)
YMax=0.0

SCAN = ScriptClip("""
Y = AverageLuma
YMax=Max(YMax,Y)
RT_WriteFile(NAME,"%d ] Y = %.2f YMax=%2.f",current_frame,Y,YMax, Append=True)
return Last
""")

# Force process SCAN clip
GScript("""
for(i=0,FrameCount-1) {
RT_YankChain(SCAN,i) # Force process SCAN clip
}
""")

# Here, any output file generated by SCAN clip processing now exists

TXT = RT_ReadTxtFromFile(NAME)
LINES=RT_TxtQueryLines(TXT)

ScriptClip("""
S=(current_frame<LINES) ? RT_TxtGetLine(TXT,Line=current_frame) : "LINE NOT FOUND"
RT_Subtitle("%s",S,align=5)
""")

return Last


I dont recommend using strings like that, its just the basic idea I was putting across, it is the GScript and RT_YankChain or similar that is required.

EDIT: You could put the GScript stuff in a script function and call it with a clip to process any clip on demand.
EDIT: eg, assign results of script 1 to SCRIPT_ONE_CLIP (or whatever), assign results of script 2 to SCRIPT_TWO_CLIP,
assign results of script 3 to SCRIPT_THREE_CLIP. Call your user func with first, clip, then with second, then either
call with third (and return a dummy eg messageclip or colorbars) or assign to Last and let it does its stuff normally.

EDIT: Like this

avisource("test.avi").trim(1000,-500) # 500 Frames

SCRIPT_1=Last.Invert # Your first script

ForceProcess(SCRIPT_1)

SCRIPT_1 = 0 # EDIT: Added, SCRIPT_1 no longer exists, ensure release of any resources (may not be necessary)

SCRIPT_2=Last.FlipHorizontal # Your Second script

ForceProcess(SCRIPT_2)

SCRIPT_2 = 0 # EDIT: Added, SCRIPT_2 no longer exists, ensure release of any resources (may not be necessary)


SCRIPT_3=Last # Your third script

return SCRIPT_3

Function ForceProcess(clip c) {
# Force process c clip
RT_DebugF("Starting Force process of clip") # EDIT: Output to DebugView (google)
GScript("""
for(i=0,c.FrameCount-1) {
RT_YankChain(c,i)
}
""")
}

goorawin
3rd February 2015, 05:36
Thank you so much for your input, It was very much appreciated.
I have got both scripts working, the first one after much trial and error. The second one is better, as you suggested. So far I have not succeeded in getting it to work in MT mode, which sadly means is is not quite as fast as the old way.

For those who may be interested, I have attached some images which show what this base script does to raw camera footage. It certainly took a lot of time to get the setting just right to cover such a wide range of different clips. The jpeg compression of these images has reduced the effect of its noise reduction.

I also have a video of the output which gives a much better example of its output.

Thank you again for your help.

StainlessS
4th February 2015, 01:28
I have no experience with MT at all, and have no idea if anything could be done in that direction to improve speed.
I suspect that what you wish for could only be achieved using some kind of external executable, which processes each script in turn.

Great results, loved the Zebra pic especially. :)

EDIT: Have implemented ForceProcess() func available in next version RT_Stats.

RT_ForceProcess(clip c,int "StartFrame"=0,Int "EndFrame"=FrameCount-1)
Scans clip c requesting frames from StartFrame to EndFrame.
c, clip to scan.
StartFrame, default 0, Frame from which to start.
EndFrame, default FrameCount-1, Last frame to scan.
Can be used to force a clip that outputs some kind of file, to produce it's output.
Returns 0.


Might be a lil bit faster than in script.