Log in

View Full Version : Correct script structure?


Bartje64
18th December 2011, 14:54
Many....thanks to Video Fred for getting me started with his scripts...

I've since modified these to suit my needs all the while learning, it has been a great adventure thus far...and the results are amazing.
Question is...what is the correct sequencing for a script especially where to "resize"....
Pending on where in the script this occurs (beginning or end) has a large impact on processing speed.

Script as follows:

Edit....figured out the "code tags"..script is below....any suggestions would be appreciated.

Thanks, Bart

kypec
19th December 2011, 06:15
Please edit your post and use CODE tags to enclose your script into it.

Bartje64
20th December 2011, 17:32
Sorry, I'm a noob to this site.

What are and how to use these "Code tags"

Bartje64
20th December 2011, 17:35
Aha....I think this is what you mean?.....


#Original file location


film="F:Videos\9.5mm Capture\New Capture\video0020.avi" # source clip, please specify the full path here

#Result....What result from this script do you want to see

result="result6" # specify the wanted output here

#Play speed
#----------------------------------------------------------

play_speed= 1.0 # What is the speed of the source clip in FPS.
final_framerate = 1.0 # What is the final frame rate you want in FPS.
# If you set these equal then there is no frame blending. Frame in = Frame out

#Trimming and bad section(s) removal
#---------------------------------------------------------

trim_begin=2 trim_end=0 # trim beginning and end frames

remove_section_1 = "Rem1_No" # Type in Rem1_Yes or Rem1_No if you do or do not want to remove a section of the clip

remove_start_1=3230 remove_stop_1=3290 # Section of clip to be removed, start frame number, stop frame number

remove_section_2 = "Rem2_No" # Type in Rem2_Yes or Rem2_No if you do or do not want to remove a section of the clip

remove_start_2=9750 remove_stop_2=9850 # Section of clip to be removed, start frame number, stop frame number

remove_section_3 = "Rem3_No" # Type in Rem3_Yes or Rem3_No if you do or do not want to remove a section of the clip

remove_start_3=9900 remove_stop_3=10736 # Section of clip to be removed, start frame number, stop frame number

#SIZE, CROP AND BORDERS PARAMETERS
#--------------------------------------

CLeft=10 CTop=24 CRight=10 CBottom=4 # crop values after trimming

W=1280 H=960 # final size after cropping 9.5mm aspect ratio is 1:3 1280-960

bord_left=8 bord_top=8 bord_right=8 bord_bot=8 # Add a border if you want to.Border size is in pixels, 720p= borders 150

#Reverse the clip
#-------------------------------------------------

Rev_Clip = "No" # Reverse the input (source) file Vertically "Yes" or "No"

# Flip the file Horizontally or Vertically
#-------------------------------------------------------

Flip_Ver = "NO" # Flip the input (source) file Vertically "Yes" or No

Flip_Hor = "yes" # Flip the output (result) file Horizontally "Yes" or No

#COLOR AND LEVELS PARAMATERS
#---------------------------------------------

saturation=1.0 # for all outputs

gamma= 1.0 # for all outputs

blue= -0 red= 0 # manual color adjustment, when returning result3 or result4. Values can be positive or negative


black_level=0 white_level=255 output_black=0 output_white=255 # manual levels, when returning result4

#CLEANING PARAMETERS
#--------------------------

dirt_blur= 0.1 # some blur before cleaning to avoid pixel artifacts
dirt_strength=300 # set this lower for clean films.

#DENOISING PARAMETERS
#------------------------------

denoising_strength= 500 # denoising level of second denoiser: MVDegrainMulti() default 400
denoising_frames=3 # number of frames for averaging (forwards and backwards) 3 is a good start value
block_size= 16 # block size of MVDegrainMulti()
block_size_v= 16
block_over= 4 # block overlapping of MVDegrainMulti()

#REMOVE SCRATCHES
#-----------------------------

Number_of_passes = "Five" # enter the number of passes through the descratch filter One, Two, Tree, Four, Five

Scratch_Width=1 # Max value is 3
scratch_blur= .5 # Max value is 1.58

# FOUR STEP SHARPENING PARAMETERS
#----------------------------

USM_sharp_ness1= 100 USM_radi_us1= 3 # first sharpening (UnsharpMask) after cleaning with removedirtMC()

USM_sharp_ness2= 80 USM_radi_us2=2 # second harpening (UnsharpMask) after cleaning with removedirtMC()

USM_sharp_ness3= 30 USM_radi_us3=1 # third sharpening (UnsharpMask) after degraining with MVDegrainMulti()


last_sharp= 0.4 # final sharpening step after degraining

last_blur= 0.1 # this smooths out the heavy sharpening effects

#STABILISING PARAMETERS
#---------------------------

maxstabH=-40
maxstabV=-40 #maximum values for the stabiliser (in pixels) 20 is a good start value

est_left=40 est_top=40 est_right=40 est_bottom=40 est_cont= 1.4 #crop and contrast values for Stabilizer Estimate clip

#AUTO LEVELS PARAMETER
#--------------------------------

X=2 # X is a special parameter for reducing the autolevels effect on the whites
X2=2 # X2 is a special parameter for reducing the autolevels effect on the blacks

# END VARIABLES, BEGIN SCRIPT
#==========================

SetMemoryMax(1024) #set this to 1/3 of the available memory


LoadPlugin("Deflicker.dll")
Loadplugin("Depan.dll")
LoadPlugin("DepanEstimate.dll")
Loadplugin("removegrain.dll")
Loadplugin("removedirts.dll")
LoadPlugin("DeScratch.dll")
LoadPlugin("MVTools.dll")
LoadPlugin("MVTools2.dll")
Loadplugin("mt_masktools.dll")
Loadplugin("warpsharp.dll")
#LoadPlugin("MT.dll")
LoadPlugin("autolevels.dll")

Import("03_RemoveDirtMC.avs")

# SetMTMode Info
# -------------------

# SetMTmode() Syntax:

# GetMTMode(bool threads)

# threads bool = false
# if true GetMTMode returns the number of threads used else the current mode is returned (see below).

# SetMTmode(int mode, int threads)


SetMTMode (2,4) #disable all MT calls if you are using a single core computer


#REMOVE ANY BAD SECTIONS
#--------------------------------

source1=AviSource(film) # This is the source file we are working with

Rem1_Yes=trim(source1,0,remove_start_1)+trim(source1,remove_stop_1,0) # Remove a section if Rem1_Yes
Rem1_No=source1

source2=Eval(Remove_section_1)

Rem2_Yes=trim(source2,0,remove_start_2)+trim(source2,remove_stop_2,0) # Remove a section if Rem2_Yes
Rem2_No=source2

source3=Eval(Remove_section_2)

Rem3_Yes=trim(source3,0,remove_start_3)+trim(source3,remove_stop_3,0) # Remove a section if Rem3_Yes
Rem3_No=source3
# Do nothing if Rem_No
#Reverse the clip
#-------------------------
# source4 is the source file we want to reverse

source4=Eval(Remove_section_3) # This is the file we want to reverse

Yes=Reverse(source4) # If "Rev_Yes", reverse the clip

No =source4 # If "Rev_No", do nothing

# Flip the file Vertically
#-----------------------------
# source5 is the source file we want to flip vertically

source5=Eval(Rev_Clip) # This is the file we want to flip vertically

Yes=flipvertical(source5) # If "FlipV_Yes", flip the file vertically

No=source5 # If "FlipV_No", do nothing

# Flip the file Horizontally
#-----------------------------
# source6 is the source file we want to flip horizontally

source6=Eval(Flip_Ver) # This is the file we want to flip horizontally

Yes=fliphorizontal(source6) # If "FlipH_Yes", flip the file horizontally

No=source6 # If "FlipH_No", do nothing

# RESIZE TRIM AND CROP
#----------------------------
# source7 is the source after trimming, reversing and flipping is completed.

source7=Eval(Flip_Hor)

Original=source1.converttoYV12().trim(trim_begin,trim_end).Lanczos4Resize(640,480) # Is the original file for comparison .crop(CLeft,CTop,-CRight,-CBottom)

Reworked=source7.converttoYV12().deflicker().assumefps(play_speed) # Is the original file ready to be reworked.

Trimmed=Reworked.trim(trim_begin,trim_end) #Trimming is completed

Ready_for_Tweak = Trimmed #Ready for tweaking

# Tweaking the color levels
#----------------------------

Tweaked= Ready_for_Tweak.levels(0,gamma,255,0,255).tweak(sat=saturation) #Tweaking is completed

#Cleaning
#--------------------

Cleaned= RemoveDirtMC(Tweaked,dirt_strength).unsharpmask(USM_sharp_ness1,USM_radi_us1,0)\
.unsharpmask(USM_sharp_ness2,USM_radi_us2,0) #Cleaning is completed

#Crop after cleaning!
#------------------------
Cropped=Cleaned.crop(CLeft,CTop,-CRight,-CBottom)
#Cropping is completed
# Scratch removal
#-----------------------------

One = Cropped.blur(scratch_blur).Descratch(mindif=Scratch_Width,maxgap=0,maxlen=10000)

Two = One.blur(scratch_blur).Descratch(mindif=Scratch_Width,maxgap=0,maxlen=10000)

Three =Two.blur(scratch_blur).Descratch(mindif=Scratch_Width,maxgap=0,maxlen=10000)

Four =Three.blur(scratch_blur).Descratch(mindif=Scratch_Width,maxgap=0,maxlen=10000)

Five =Four.blur(scratch_blur).Descratch(mindif=Scratch_Width,maxgap=0,maxlen=10000) #CScratch removal is completed

#degraining/denoising
#---------------------------

Descratch_Passes = Eval(Number_of_passes)


Vectors= Descratch_Passes.MvAnalysemulti(refframes=denoising_frames, pel=2, blksize=block_size, blksizev= block_size_v, overlap=block_over, idx=1)
Denoised= Descratch_Passes.MVDegrainMulti(vectors, thSAD=denoising_strength, SadMode=1, idx=2).unsharpmask(USM_sharp_ness3,USM_radi_us3,0)

Rework_Done=Denoised.sharpen(last_sharp).sharpen(last_sharp) #Degraining,denoising,last sharpening completed.

#STABILIZING
#------------------------

Stab_Reference= Rework_Done.crop(est_left,est_top,-est_right,-est_bottom).tweak(cont=est_cont).MT_binarize(threshold=80).invert().greyscale()

mdata=DePanEstimate(Stab_Reference,range=2,trust=3,dxmax=maxstabH,dymax=maxstabV)

Stab_Ref=DePanStabilize(Rework_Done,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=0,info=true) #Reference file for result5

Stabilized=DePanStabilize(Rework_Done,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=0,mirror=15) #Stabilizing is completed

#Stabilizing Info for Results5
#-----------------------------

WS=width(Stab_Ref)
HS=height(Stab_Ref)
stab4= Stab_Ref.addborders(10,10,10,10,$B1B1B1).Lanczos4Resize(WS,HS)
stab5= Lanczos4Resize(Stabilized,WS,HS).sharpen(0.5)

#Resize
#----------------------

Work_completed=Stabilized

#Add borders
#-------------------------

#Borders=Rework_Done.addborders(bord_left, bord_top, bord_right, bord_bot) # Add borders

#Results
#-----------------------


#RESULT1: AUTOLEVELS, AUTOWHITE
result1= Work_completed.coloryuv(autowhite=true).addborders(X,0,0,0,$FFFFFF).addborders(0,0,X2,0,$000000).autolevels().crop(X,0,-X2,-0)\
.converttoYUY2().blur(last_blur).converttoYV12().addborders(bord_left, bord_top, bord_right, bord_bot).ConvertFPS(final_framerate)

#RESULT2: MANUAL LEVELS, AUTOWHITE
#................................
result2= Work_completed.levels(black_level,1.0,white_level,0,255).coloryuv(autowhite=true)\
.converttoYUY2().blur(last_blur).converttoYV12().addborders(bord_left, bord_top, bord_right, bord_bot).ConvertFPS(final_framerate)

#RESULT3: AUTOLEVELS, MANUAL COLOR CORRECTIONS
#.......................................Work_completed.coloryuv(off_U=blue,off_V=red).addborders(X,0,0,0,$FFFFFF).addborders(0,0,X2,0,$000000).autolevels().crop(X,0,-X2,-0)\
.converttoYUY2().blur(last_blur).converttoYV12().addborders(bord_left, bord_top, bord_right, bord_bot).ConvertFPS(final_framerate)

#RESULT4: MANUAL LEVELS, MANUAL COLOR CORRECTIONS
#..................................................................................................................................................
result4= Work_completed.coloryuv(off_U=blue,off_V=red).levels(black_level,1.0,white_level,0,255).ConvertFPS(final_framerate)\
.converttoYUY2().ConvertFPS(final_framerate).blur(last_blur).converttoYV12().addborders(bord_left, bord_top, bord_right, bord_bot)

#RESULT5: SPECIAL SERVICE CLIP FOR RESULT S5
#..................................................................................................................................................
result5= overlay(Rework_Done,stab_reference,x=est_left,y=est_top).addborders(2,2,2,2,$FFFFFF).Lanczos4Resize(WS,HS)



#COMPARISONS: ORIGINAL VS RESULTS
#......................................................................................................................................................................
resultS1= stackhorizontal(subtitle(Original,"original",size=28,align=2),subtitle(result1.Lanczos4Resize(640,480),"result1: autolevels, autowhite",size=28,align=2))
resultS2= stackhorizontal(subtitle(Original,"original",size=28,align=2),subtitle(result2.Lanczos4Resize(640,480),"resuls2: autowhite, manual levels correction",size=28,align=2))
resultS3= stackhorizontal(subtitle(Original,"original",size=28,align=2),subtitle(result3.Lanczos4Resize(640,480),"result3: autolevels, manual color correction",size=28,align=2))
resultS4= stackhorizontal(subtitle(Original,"original",size=28,align=2),subtitle(result4.Lanczos4Resize(640,480),"result4: manual colors and levels correction",size=28,align=2))

#SPECIAL COMPARISON CLIP FOR TESTING THE STABILIZER
#.........................................................................................................................................................................
resultS5= stackhorizontal(subtitle(result5,"baseclip for stabiliser -only the B/W clip is used",size=32,align=2),subtitle(stab4,"test stabiliser: dx=horizontal, dy=vertical",size=32,align=5))


#Result6: rezize after all work is completed
#----------------------------------------------------------------------------------------------------

Result6=result4.Lanczos4Resize(W,H)


SetMTMode(6)

Eval(result)

redfordxx
21st December 2011, 01:07
I really didn't read but my opinion is following:
1.Source including postprocessing as a part of decoding
2.Postprocessing
3.Crop
4.Postprocessing
5.trim and other frame reordering activities
6.Crop
7.Resize
8.Postprocessing?
Postprocessing can be deblocking, denoising, deinterlacing, deringing, depan, color correction or whatever
The particular order should be decided based on the source nature, that cannot be general
If you are downsizing there should be no step (8), unless you wanna save some processing time. In case of upsizing, exceptionally there might be reason...
Deblocking might be beste in step one, deringing probably also..