Guest User

Untitled

a guest
May 8th, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.70 KB | None | 0 0
  1. # 8mm film restoration script by videoFred.
  2. # www.super-8.be
  3.  
  4. # version 01.A with frame interpolation
  5. # release date: june 20, 2012
  6. #============================================================================================
  7.  
  8. # august 2010: added removerdirtMC() as suggested by John Meyer
  9. # october 2010: auto sharpening parameters
  10.  
  11. # march 2011: new autolevels.dll by Jim Battle
  12. # www.thebattles.net/video/autolevels.html
  13.  
  14. # june 2012: improved stabilisation
  15.  
  16.  
  17. #=============================================================================================
  18.  
  19. # cleaning, degraining, resizing, stabilizing, sharpening, auto-levels and auto-white balance.
  20. #=============================================================================================
  21.  
  22.  
  23. film= "C:\Users\Arestia\Downloads\MIND OF EVIL 2014.avi" # source clip, you must specify the full path here
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. #PARAMETERS
  31. #----------------------------------------------------------------------------------------------------------------------------
  32. result="resultS1" # specify the wanted output here
  33.  
  34. trim_begin=2 trim_end=10 play_speed=18 #trim frames and play speed (PAL: 16.6666 or 18.75)
  35.  
  36. numerator= 25 #numerator for the interpolator (final frame rate)
  37. denumerator= 1 #denumerator example: 60000/1001= 59.94fps
  38.  
  39.  
  40. #COLOR AND LEVELS PARAMATERS
  41. #----------------------------------------------------------------------------------------------------------------------------
  42. saturation=1.2 #for all outputs
  43.  
  44. gamma= 1.2 # for all outputs
  45.  
  46. blue= 0 red= 0 #manual color adjustment, when returning result3 or result4. Values can be positive or negative
  47.  
  48.  
  49. black_level=0 white_level=255 output_black=0 output_white=255 # manual levels, when returning result4
  50.  
  51.  
  52. #AUTO LEVELS PARAMETERS
  53. #--------------------------------------------------------------------------------------------------------------------------------
  54.  
  55. autolev_low= 6 # limit of autolevels low output
  56. autolev_high= 235 # limit of autolevels high output
  57.  
  58.  
  59.  
  60. #SIZE, CROP AND BORDERS PARAMETERS
  61.  
  62. #----------------------------------------------------------------------------------------------------------------------------
  63. CLeft=32 CTop=32 CRight=32 CBottom=32 #crop values after Depan and before final resizing
  64.  
  65. W=720 H=576 #final size after cropping
  66.  
  67. bord_left=0 bord_top=0 bord_right=0 bord_bot=0 #720p= borders 150
  68.  
  69.  
  70. #STABILISING PARAMETERS, YOU REALY MUST USE RESULTS7 TO CHECK STABILISATION!
  71.  
  72. /*
  73. maxstabH=20
  74. maxstabV=20 #maximum values for the stabiliser (in pixels) 20 is a good start value
  75.  
  76. est_left=20 est_top=60 est_right=60 est_bottom=60 #crop values for special Estimate clip
  77.  
  78. trust_value= 1.0 # scene change detection, higher= more sensitive
  79. cutoff_value= 0.5 # no need to change this, but you can play with it and see what you get
  80.  
  81.  
  82.  
  83. */ est_left=0 est_top=0 est_right=0 est_bottom=0 #crop values for special Estimate clip
  84.  
  85.  
  86.  
  87. #CLEANING PARAMETERS
  88. #--------------------------------------------------------------------------------------------------------------
  89.  
  90. dirt_strenght=30 # set this lower for clean films.
  91.  
  92.  
  93. #DENOISING PARAMETERS
  94. #----------------------------------------------------------------------------------------------------------------------------
  95.  
  96.  
  97. denoising_strenght= 300 #denoising level of second denoiser: MVDegrainMulti()
  98. denoising_frames= 3 #number of frames for averaging (forwards and backwards) 3 is a good start value
  99. block_size= 16 #block size of MVDegrainMulti()
  100. block_size_v= 16
  101. block_over= 8 #block overlapping of MVDegrainMulti()
  102.  
  103.  
  104.  
  105.  
  106. # SHARPENING PARAMETERS
  107. #--------------------------------------------------------------------------------------------------------------------------------
  108.  
  109. USM_sharp_ness= 40 USM_radi_us=3 #this is the start value for the unsharpmask sharpening
  110. #do not set radius less then 3
  111. #the script will automatically add two other steps with lower radius
  112.  
  113.  
  114.  
  115. last_sharp= 0.1 #final sharpening step after interpolation
  116.  
  117. last_blur= 0.2 #this smooths out the heavy sharpening effects
  118.  
  119.  
  120.  
  121.  
  122.  
  123. # END VARIABLES, BEGIN SCRIPT
  124. #=================================================================================================================================
  125.  
  126.  
  127. SetMemoryMax(3000) #set this to 1/3 of the available memory
  128.  
  129.  
  130.  
  131.  
  132. LoadPlugin("plugins/Deflicker.dll")
  133. #Loadplugin("plugins/Depan.dll")
  134. #LoadPlugin("plugins/DepanEstimate.dll")
  135. Loadplugin("plugins/removegrain.dll")
  136. LoadPlugin("plugins/removedirt.dll")
  137. LoadPlugin("plugins/MVTools.dll")
  138. LoadPlugin("plugins/MVTools2.dll")
  139. Loadplugin("plugins/warpsharp.dll")
  140. LoadPlugin("plugins/autolevels_06.dll")
  141. Import("plugins/03_RemoveDirtMC.avs")
  142.  
  143.  
  144.  
  145.  
  146. source= AviSource(film).assumefps(play_speed).trim(trim_begin,0).converttoYV12()
  147. trimming= framecount(source)-trim_end
  148. source1= trim(source,0,trimming)
  149.  
  150. #STABILIZING/CROPPING
  151. #...........................................................................................................................................
  152. stab2= source1#.crop(CLeft,CTop,-CRight,-CBottom)
  153. stab3= stab2
  154.  
  155. #stab_reference= source1.crop(20,20,-20,-20).colorYUV(autogain=true).crop(est_left,est_top,-est_right,-est_bottom)
  156.  
  157. stab_reference= source1#.crop(0,0,0,0).colorYUV(autogain=true).crop(est_left,est_top,-est_right,-est_bottom)
  158.  
  159. /*
  160.  
  161. mdata=DePanEstimate(stab_reference,trust=trust_value,dxmax=maxstabH,dymax=maxstabV)
  162. stab=DePanStabilize(source1,data=mdata,cutoff=cutoff_value,dxmax=maxstabH,dymax=maxstabV,method=0,mirror=15).deflicker()
  163. stab2= stab.crop(CLeft,CTop,-CRight,-CBottom)
  164. stab3=DePanStabilize(source1,data=mdata,cutoff=cutoff_value,dxmax=maxstabH,dymax=maxstabV,method=0,info=true)
  165.  
  166.  
  167. WS= width(stab)
  168. HS= height(stab)
  169.  
  170. */
  171.  
  172. WS= width(stab2)
  173. HS= height(stab2)
  174.  
  175.  
  176. #stab4= stab3.addborders(10,10,10,10,$B1B1B1).Lanczos4Resize(WS,HS)
  177. #stab5= Lanczos4Resize(stab2,W,H).sharpen(0.5)
  178.  
  179. stab4=stab2
  180. stab5=stab2
  181.  
  182. #stab2= stab.crop(0,0,0,0)
  183.  
  184. #UNSHARPMASK AUTO_PARAMETERS
  185. #-------------------------------------------------------------------------------------------------------------------------------------------
  186.  
  187. USM_sharp_ness1 = USM_sharp_ness
  188. USM_sharp_ness2 = USM_sharp_ness+(USM_sharp_ness/2)
  189. USM_sharp_ness3 = USM_sharp_ness*2
  190.  
  191. USM_radi_us1 = USM_radi_us
  192. USM_radi_us2 = USM_radi_us-1
  193. USM_radi_us3 = USM_radi_us2-1
  194.  
  195.  
  196. #CLEANING/PRESHARPENING/RESIZING
  197. #..........................................................................................................................................
  198.  
  199. noise_baseclip= stab2.levels(0,gamma,255,0,255).tweak(sat=saturation)
  200.  
  201.  
  202. cleaned= RemoveDirtMC(noise_baseclip,dirt_strenght).unsharpmask(USM_sharp_ness1,USM_radi_us1,0)\
  203. .unsharpmask(USM_sharp_ness2,USM_radi_us2,0).Lanczos4Resize(W,H)
  204.  
  205.  
  206. #DEGRAINING/SHARPENING
  207. #...................................................................................................................................................................
  208.  
  209.  
  210. vectors= cleaned.MVAnalyseMulti(refframes=denoising_frames, pel=2, blksize=block_size, blksizev= block_size_v, overlap=block_over, idx=1)
  211. denoised= cleaned.MVDegrainMulti(vectors, thSAD=denoising_strenght, SadMode=1, idx=2).unsharpmask(USM_sharp_ness3,USM_radi_us3,0)
  212.  
  213.  
  214. #CHANGING FRAME RATE WITH INTERPOLATION/FINALSHARPENING
  215. #............................................................................................................................................................
  216.  
  217. super= denoised.MSuper()
  218. backward_vec= MAnalyse(super, blksize=block_size, blksizev= block_size_v, overlap=block_over, isb=true)
  219. forward_vec= MAnalyse(super,blksize=block_size, blksizev= block_size_v, overlap=block_over, isb= false)
  220.  
  221. interpolated= denoised.MFlowFps(super, backward_vec, forward_vec, num=numerator, den= denumerator, ml=100)\
  222. .sharpen(last_sharp,mmx=false).sharpen(last_sharp,mmx=false).blur(last_blur,mmx=false)
  223.  
  224.  
  225. #RESULT1: AUTOLEVELS,AUTOWHITE
  226. #......................................................................................................................................................................
  227. result1= interpolated.converttoRGB24().autolevels(output_low= autolev_low, output_high= autolev_high)\
  228. .converttoYV12().coloryuv(autowhite=true).addborders(bord_left, bord_top, bord_right, bord_bot)
  229.  
  230. #RESULT2: MANUAL LEVELS, AUTOWHITE
  231. #......................................................................................................................................................................
  232. result2= interpolated.levels(black_level,1.0,white_level,0,255).coloryuv(autowhite=true)\
  233. .addborders(bord_left, bord_top, bord_right, bord_bot)
  234.  
  235. #RESULT3: AUTOLEVELS, MANUAL COLOR CORRECTIONS
  236. #.....................................................................................................................................................................
  237. result3= interpolated.coloryuv(off_U=blue,off_V=red).converttoRGB24().autolevels(output_low= autolev_low, output_high= autolev_high)\
  238. .converttoYV12().addborders(bord_left, bord_top, bord_right, bord_bot)
  239.  
  240. #RESULT4: MANUAL LEVELS, MANUAL COLOR CORRECTIONS
  241. #.....................................................................................................................................................................
  242. result4= interpolated.coloryuv(off_U=blue,off_V=red).levels(black_level,1.0,white_level,0,255)\
  243. .addborders(bord_left, bord_top, bord_right, bord_bot)
  244.  
  245. #RESULT5: SPECIAL SERVICE CLIP FOR RESULT S5
  246. #.....................................................................................................................................................................
  247. result5= overlay(source1,greyscale(stab_reference),x=est_left,y=est_top).addborders(2,2,2,2,$FFFFFF).Lanczos4Resize(WS,HS)
  248.  
  249.  
  250. #PARAMETERS FOR THE COMPARISONS
  251. #.....................................................................................................................................................................
  252. W2= W+bord_left+bord_right
  253. H2= H+bord_top+bord_bot
  254.  
  255.  
  256. final_framerate= numerator/denumerator
  257. source4=Lanczos4Resize(source1,W2,H2).changeFPS(final_framerate)
  258.  
  259.  
  260.  
  261. #COMPARISONS: ORIGINAL VS RESULTS
  262. #......................................................................................................................................................................
  263. resultS1= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result1,"result1: autolevels, autowhite",size=28,align=2))
  264. resultS2= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result2,"result2: autowhite, manual levels correction",size=28,align=2))
  265. resultS3= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result3,"result3: autolevels, manual color correction",size=28,align=2))
  266. resultS4= stackhorizontal(subtitle(source4,"original",size=28,align=2),subtitle(result4,"result4: manual colors and levels correction",size=28,align=2))
  267. resultS5= stackhorizontal(subtitle(result3,"result3: auto levels, manual color correction",size=28,align=2),subtitle(result4,"result4: manual colors and levels correction",size=28,align=2))
  268. resultS6= stackhorizontal(subtitle(result1,"result1: autolevels, autowhite",size=28,align=2),subtitle(result2,"result2: manual levels, autowhite",size=28,align=2))
  269.  
  270. #SPECIAL COMPARISON CLIP FOR TESTING THE STABILIZER
  271. #.........................................................................................................................................................................
  272. resultS7= stackhorizontal(subtitle(result5,"baseclip for stabiliser -only the B/W clip is used",size=32,align=2),\
  273. subtitle(stab4,"test stabiliser: dx=horizontal, dy=vertical",size=32,align=5)).converttoYUY2()
  274.  
  275.  
  276.  
  277. Eval(result)#.converttoRGB24()
  278.  
  279.  
  280. return result4
  281.  
  282.  
  283.  
Advertisement
Add Comment
Please, Sign In to add comment