Advertisement
Guest User

Untitled

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