Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.24 KB | None | 0 0
  1. # film restoration script by videoFred.
  2. # version with frame interpolation
  3. # modified 30 august 2010
  4. # added removedirtMC() as suggested by John Meyer
  5. # cleaning, degraining, resizing, stabilizing, sharpening, auto-levels and auto-white balance.
  6. #=============================================================================================
  7.  
  8.  
  9. film="C:\Documents and Settings\All Users\Desktop\test.avi" # source clip, please specify the full path here
  10.  
  11.  
  12. #PARAMETERS
  13. #----------------------------------------------------------------------------------------------------------------------------
  14. result="resultS3" # specify the wanted output here
  15.  
  16. trim_begin=2 play_speed=18.75 #trim frames and play speed (PAL: 16.6666 or 18.75)
  17.  
  18. numerator= 25 #numerator for the interpolator (final frame rate)
  19. denumerator= 1 #denumerator example: 60000/1001= 59.94fps
  20.  
  21.  
  22. #COLOR AND LEVELS PARAMATERS
  23. #----------------------------------------------------------------------------------------------------------------------------
  24. saturation=1.2 #for all outputs
  25.  
  26. gamma= 1.0 # for all outputs
  27.  
  28. blue= -0 red= -0 #manual color adjustment, when returning result3 or result4. Values can be positive or negative
  29.  
  30.  
  31. black_level=0 white_level=255 output_black=0 output_white=255 # manual levels, when returning result4
  32.  
  33.  
  34. #SIZE, CROP AND BORDERS PARAMETERS
  35. #----------------------------------------------------------------------------------------------------------------------------
  36. CLeft=20 CTop=20 CRight=20 CBottom=20 #crop values after Depan and before final resizing
  37.  
  38. W=720 H=576 #final size after cropping
  39.  
  40. bord_left=0 bord_top=0 bord_right=0 bord_bot=0 #720p= borders 150
  41.  
  42.  
  43. #STABILISING PARAMETERS
  44. #----------------------------------------------------------------------------------------------------------------------------
  45. maxstabH=20
  46. maxstabV=20 #maximum values for the stabiliser (in pixels) 20 is a good start value
  47.  
  48. est_left=40 est_top=40 est_right=40 est_bottom=40 est_cont=1.4 #crop and contast values for special Estimate clip
  49.  
  50.  
  51. #CLEANING PARAMETERS
  52. #--------------------------------------------------------------------------------------------------------------
  53.  
  54. dirt_blur= 0.1 # some blur before cleaning to avoid pixel artifacts
  55. dirt_strength=40 # set this lower for clean films.
  56.  
  57.  
  58. #DENOISING PARAMETERS
  59. #----------------------------------------------------------------------------------------------------------------------------
  60.  
  61.  
  62. denoising_strength= 900 #denoising level of second denoiser: MVDegrainMulti()
  63. denoising_frames= 3 #number of frames for averaging (forwards and backwards) 3 is a good start value
  64. block_size= 16 #block size of MVDegrainMulti()
  65. block_size_v= 16
  66. block_over= 8 #block overlapping of MVDegrainMulti()
  67.  
  68.  
  69.  
  70.  
  71. # FOUR STEP SHARPENING PARAMETERS
  72. #--------------------------------------------------------------------------------------------------------------------------------
  73.  
  74. USM_sharp_ness1= 120 USM_radi_us1= 3 #first sharpening (UnsharpMask) after cleaning with removedirtMC()
  75.  
  76. USM_sharp_ness2= 80 USM_radi_us2=2 #second harpening (UnsharpMask) after cleaning with removedirtMC()
  77.  
  78. USM_sharp_ness3= 70 USM_radi_us3=1 #third sharpening (UnsharpMask) after degraining with MVDegrainMulti()
  79.  
  80.  
  81. last_sharp= 0.4 #final sharpening step after interpolation
  82.  
  83. last_blur= 0.2 #this smooths out the heavy sharpening effects
  84.  
  85.  
  86.  
  87. #AUTO LEVELS PARAMETER
  88. #--------------------------------------------------------------------------------------------------------------------------------
  89. X=2 # X is a special parameter for reducing the autolevels effect on the whites
  90. X2=2 # X2 is a special parameter for reducing the autolevels effect on the blacks
  91.  
  92.  
  93.  
  94.  
  95. # END VARIABLES, BEGIN SCRIPT
  96. #=================================================================================================================================
  97.  
  98.  
  99. SetMemoryMax(800) #set this to 1/3 of the available memory
  100.  
  101. #SetMTMode(5) #disable all MT calls if you are using a single core computer
  102.  
  103. LoadPlugin("Deflicker.dll")
  104. Loadplugin("Depan.dll")
  105. LoadPlugin("DepanEstimate.dll")
  106. Loadplugin("removegrain.dll")
  107. LoadPlugin("removedirt.dll")
  108. LoadPlugin("MVTools.dll")
  109. LoadPlugin("MVTools2.dll")
  110. Loadplugin("mt_masktools.dll")
  111. Loadplugin("warpsharp.dll")
  112. LoadPlugin("MT.dll")
  113. LoadPlugin("autolevels.dll")
  114. Import("03_RemoveDirtMC.avs")
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. source1= DirectShowSource("C:\Documents and Settings\All Users\Desktop\test.avi").assumefps(play_speed).trim(trim_begin,0).converttoYV12()
  122.  
  123.  
  124. #SetMTMode(1,0)
  125.  
  126.  
  127. #STABILIZING/CROPPING
  128. #...........................................................................................................................................
  129. stab_reference= source1.crop(est_left,est_top,-est_right,-est_bottom).tweak(cont=est_cont).MT_binarize(threshold=80).greyscale().invert()
  130.  
  131. mdata=DePanEstimate(stab_reference,trust=1.0,dxmax=maxstabH,dymax=maxstabV)
  132. stab=DePanStabilize(source1,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=0,mirror=15).deflicker()
  133. stab2= stab.crop(CLeft,CTop,-CRight,-CBottom)
  134. stab3=DePanStabilize(source1,data=mdata,cutoff=0.5,dxmax=maxstabH,dymax=maxstabV,method=0,info=true)
  135.  
  136. WS= width(stab)
  137. HS= height(stab)
  138. stab4= stab3.addborders(10,10,10,10,$B1B1B1).Lanczos4Resize(WS,HS)
  139. stab5= Lanczos4Resize(stab2,W,H).sharpen(0.5)
  140.  
  141.  
  142. #CLEANING/PRESHARPENING/RESIZING
  143. #..........................................................................................................................................
  144.  
  145.  
  146. noise_baseclip= stab2.levels(0,gamma,255,0,255).tweak(sat=saturation).blur(dirt_blur)
  147.  
  148.  
  149.  
  150.  
  151. cleaned= RemoveDirtMC(noise_baseclip,dirt_strength).unsharpmask(USM_sharp_ness1,USM_radi_us1,0)\
  152. .unsharpmask(USM_sharp_ness2,USM_radi_us2,0).Lanczos4Resize(W,H)
  153.  
  154.  
  155.  
  156. #DEGRAINING/SHARPENING
  157. #...................................................................................................................................................................
  158.  
  159.  
  160. vectors= cleaned.MVAnalyseMulti(refframes=denoising_frames, pel=2, blksize=block_size, blksizev= block_size_v, overlap=block_over, idx=1)
  161. denoised= cleaned.MVDegrainMulti(vectors, thSAD=denoising_strength, SadMode=1, idx=2).unsharpmask(USM_sharp_ness3,USM_radi_us3,0)
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168. #CHANGING FRAME RATE WITH INTERPOLATION/FINALSHARPENING
  169. #............................................................................................................................................................
  170.  
  171. super= denoised.MSuper()
  172. backward_vec= MAnalyse(super, blksize=block_size, blksizev= block_size_v, overlap=block_over, isb=true)
  173. forward_vec= MAnalyse(super,blksize=block_size, blksizev= block_size_v, overlap=block_over, isb= false)
  174.  
  175. interpolated= denoised.MFlowFps(super, backward_vec, forward_vec, num=numerator, den= denumerator, ml=100)\
  176. .sharpen(last_sharp).sharpen(last_sharp).blur(last_blur)
  177.  
  178.  
  179. #RESULT1: AUTOLEVELS,AUTOWHITE
  180. #......................................................................................................................................................................
  181. result1= interpolated.coloryuv(autowhite=true).addborders(X,0,0,0,$FFFFFF).addborders(0,0,X2,0,$000000)\
  182. .autolevels().crop(X,0,-X2,-0).addborders(bord_left, bord_top, bord_right, bord_bot)
  183.  
  184. #RESULT2: MANUAL LEVELS, AUTOWHITE
  185. #......................................................................................................................................................................
  186. result2= interpolated.levels(black_level,1.0,white_level,0,255).coloryuv(autowhite=true)\
  187. .addborders(bord_left, bord_top, bord_right, bord_bot)
  188.  
  189. #RESULT3: AUTOLEVELS, MANUAL COLOR CORRECTIONS
  190. #.....................................................................................................................................................................
  191. result3= interpolated.coloryuv(off_U=blue,off_V=red).addborders(X,0,0,0,$FFFFFF)\
  192. .addborders(0,0,X2,0,$000000).autolevels().crop(X,0,-X2,-0).addborders(bord_left, bord_top, bord_right, bord_bot)
  193.  
  194. #RESULT4: MANUAL LEVELS, MANUAL COLOR CORRECTIONS
  195. #.....................................................................................................................................................................
  196. result4= interpolated.coloryuv(off_U=blue,off_V=red).levels(black_level,1.0,white_level,0,255)\
  197. .addborders(bord_left, bord_top, bord_right, bord_bot)
  198.  
  199. #RESULT5: SPECIAL SERVICE CLIP FOR RESULT S5
  200. #.....................................................................................................................................................................
  201. result5= overlay(source1,stab_reference,x=est_left,y=est_top).addborders(2,2,2,2,$FFFFFF).Lanczos4Resize(WS,HS)
  202.  
  203.  
  204.  
  205.  
  206. #PARAMETERS FOR THE COMPARISONS
  207. #.....................................................................................................................................................................
  208. W2= W+bord_left+bord_right
  209. H2= H+bord_top+bord_bot
  210.  
  211.  
  212.  
  213.  
  214. final_framerate= numerator/denumerator
  215. source4=Lanczos4Resize(source1,W2,H2).changeFPS(final_framerate)
  216.  
  217.  
  218.  
  219. #COMPARISONS: ORIGINAL VS RESULTS
  220. #......................................................................................................................................................................
  221. resultS1= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result1,"result1: autolevels, autowhite",size=28,align=2))
  222. resultS2= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result2,"result2: autowhite, manual levels correction",size=28,align=2))
  223. resultS3= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result3,"result3: autolevels, manual color correction",size=28,align=2))
  224. resultS4= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result4,"result4: manual colors and levels correction",size=28,align=2))
  225.  
  226.  
  227. #SPECIAL COMPARISON CLIP FOR TESTING THE STABILIZER
  228. #.........................................................................................................................................................................
  229. resultS5= stackhorizontal(subtitle(result5,"baseclip for stabiliser -only the B/W clip is used",size=32,align=2),\
  230. subtitle(stab4,"test stabiliser: dx=horizontal, dy=vertical",size=32,align=5))
  231.  
  232. #SetMTMode(5)
  233.  
  234. Eval(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement