Advertisement
FranceBB1

Restoring old 8mm films by Fred Van de Putte

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