Advertisement
Guest User

Untitled

a guest
Mar 12th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. # Imports
  2. import vapoursynth as vs
  3. import os
  4. import ctypes
  5. # Loading Support Files
  6. Dllref = ctypes.windll.LoadLibrary("i:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
  7. import sys
  8. # getting Vapoursynth core
  9. core = vs.core
  10. # Import scripts folder
  11. scriptPath = 'i:/Hybrid/64bit/vsscripts'
  12. sys.path.insert(0, os.path.abspath(scriptPath))
  13. # Loading Plugins
  14. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
  15. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
  16. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
  17. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/FFT3DFilter/fft3dfilter.dll")
  18. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
  19. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
  20. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
  21. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
  22. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
  23. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
  24. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/EEDI2.dll")
  25. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
  26. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
  27. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libsangnom.dll")
  28. core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
  29. # Import scripts
  30. import havsfunc
  31. import muvsfunc
  32. import mvsfunc
  33. # source: 'C:\Users\Selur\Desktop\00000.m2ts'
  34. # current color space: YUV420P8, bit depth: 8, resolution: 1920x1080, fps: 29.97, color matrix: 709, yuv luminance scale: limited, scanorder: top field first
  35. # Loading C:\Users\Selur\Desktop\00000.m2ts using DGSource
  36. clip = core.dgdecodenv.DGSource("J:/tmp/m2ts_68893d65f4c2ef02e134e5f06b5e1b0f_853323747.dgi",fieldop=0)# 29.97 fps, scanorder: top field first
  37. # Setting detected color matrix (709).
  38. clip = core.std.SetFrameProps(clip, _Matrix=1)
  39. # Setting color transfer info (709), when it is not set
  40. clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=1)
  41. # Setting color primaries info (BT.709), when it is not set
  42. clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=1)
  43. # Setting color range to TV (limited) range.
  44. clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
  45. # making sure frame rate is set to 29.97
  46. clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
  47. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  48. # converting interlaced to half-height progressive for filtering (vsMAA) (separate fields)
  49. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P8, range_s="limited")
  50. clip = core.std.SeparateFields(clip, tff=True)
  51. clipEven = clip[::2] # resolution 1920x540
  52. clipEven = core.std.SetFrameProp(clip=clipEven, prop="_FieldBased", intval=0) # progressive
  53. clipOdd = clip[1::2] # resolution 1920x540
  54. clipOdd = core.std.SetFrameProp(clip=clipOdd, prop="_FieldBased", intval=0) # progressive
  55. # Anti Aliasing using MAA
  56. clipEven = muvsfunc.maa(clipEven)
  57. # Anti Aliasing using MAA
  58. clipOdd = muvsfunc.maa(clipOdd)
  59. clipEven = core.std.AddBorders(clip=clipEven, left=0, right=0, top=2, bottom=2) # add borders to archive mod 16 (vsSangNom) - 1920x544
  60. # applying AA using SangNom
  61. clipEven = core.sangnom.SangNom(clip=clipEven, aa=[48,24])
  62. clipEven = core.std.CropRel(clip=clipEven, left=0, right=0, top=2, bottom=2) # removing borders (vsSangNom) - 1920x540
  63. clipOdd = core.std.AddBorders(clip=clipOdd, left=0, right=0, top=2, bottom=2) # add borders to archive mod 16 (vsSangNom) - 1920x544
  64. # applying AA using SangNom
  65. clipOdd = core.sangnom.SangNom(clip=clipOdd, aa=[48,24])
  66. clipOdd = core.std.CropRel(clip=clipOdd, left=0, right=0, top=2, bottom=2) # removing borders (vsSangNom) - 1920x540
  67. # applying anti aliasing using santiag
  68. clipEven = havsfunc.santiag(c=clipEven, qual=2, pscrn=2, aa=53, opencl=True)
  69. # applying anti aliasing using santiag
  70. clipOdd = havsfunc.santiag(c=clipOdd, qual=2, pscrn=2, aa=53, opencl=True)
  71. # converting half-height progressive to interlacedbefore deinterlacing
  72. clip = core.std.Interleave([clipOdd, clipEven])
  73. clip = core.std.DoubleWeave(clip=clip, tff=True) # resolution 1920x1080
  74. clip = core.std.SelectEvery(clip, 2, 0)
  75. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2) # tff
  76. # Deinterlacing using QTGMC
  77. clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 59.94
  78. # Making sure content is preceived as frame based
  79. clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=0) # progressive
  80. # adjusting frame count and rate with sRestore
  81. clip = havsfunc.srestore(source=clip, frate=23.9760, omode=6, speed=9, thresh=16, mode=2)
  82. # cropping the video to 1432x814
  83. clip = core.std.CropRel(clip=clip, left=244, right=244, top=134, bottom=132)
  84. ## Starting applying 'EdgeMask (Sobel)' masked filtering for vsBasicVSRPPFilter
  85. clipMask = clip
  86. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.RGBS, matrix_in_s="709", range_s="limited")
  87. clipMask = core.std.Sobel(clip=clipMask)
  88. clipMask = core.std.Maximum(clipMask)
  89. clipMask = core.resize.Bicubic(clip=clipMask, format=vs.GRAYS, matrix_s="709", range_s="limited")
  90. clipFiltered = clip
  91. clipFiltered = core.std.AddBorders(clip=clipFiltered, left=0, right=0, top=2, bottom=4) # add borders to archive mod 8 (vsBasicVSRPPFilter) - 1432x820
  92. # adjusting color space from YUV444P8 to RGBS for vsBasicVSRPPFilter
  93. clipFiltered = core.resize.Bicubic(clip=clipFiltered, format=vs.RGBS, matrix_in_s="709", range_s="limited")
  94. # Quality enhancement using BasicVSR++
  95. from vsbasicvsrpp import BasicVSRPP
  96. clipFiltered = BasicVSRPP(clip=clipFiltered, model=3, interval=1, fp16=True)
  97. clipFiltered = core.std.CropRel(clip=clipFiltered, left=0, right=0, top=2, bottom=4) # removing borders (vsBasicVSRPPFilter) - 1432x814
  98. clip = core.resize.Bicubic(clip=clip, format=vs.RGBS, matrix_in_s="709", range_s="limited")
  99. clip = core.std.MaskedMerge(clip, clipFiltered, clipMask) # Sobel
  100. ## Finished applying 'Edgemask (Sobel)' masked filtering for vsBasicVSRPPFilter
  101. # adjusting color space from RGBS to YUV444P16 for vsGLSLDarken
  102. clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="709", range_s="limited", dither_type="error_diffusion")
  103. # Using Anime4k Darken GLSL filter for line darkening
  104. with open("i:/Hybrid/64bit/vsfilters/GLSL/parameterized/Anime4K_Darken_HQ.glsl") as glslf:
  105. glsl = glslf.read()
  106. glsl = glsl.replace('#define STRENGTH 1.5', '#define STRENGTH 2.5')
  107. clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
  108. # adjusting output color from: YUV444P16 to YUV420P8 for x264Model
  109. clip = core.resize.Bicubic(clip=clip, dither_type="error_diffusion", format=vs.YUV420P8, range_s="limited")
  110. # set output frame rate to 23.976fps (progressive)
  111. clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
  112. # Output
  113. clip.set_output()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement