######################################################################
# First, you need DGIndex to prepare the d2v index file from the ISO.
# Then, here in the script, you need to correct the DLL paths for DGDecode and Yadif, and for the d2v path and video name.
# Occasionally, you will need a different DGIdex + DGDecode version.
# With avsproxy, you feed this into Avidemux 2.7.0 (caveat - connect, before opening the py project file).
# In the py or settings, set video length (A-B buttons), select quality (19-22), output format NTSC 16/9 (or 3/4),
# and adjust color correction and border cutting in the plugins.
# For a different Avidemux version the py file is probably invalid, and you need to re-enter all my parameters manually.
#LoadPlugin("F:\programs\AviSynth+\plugins+\DGDecode154.dll")
#LoadPlugin("F:\programs\AviSynth+\plugins+\dgdecode58.dll")
LoadPlugin("D:\Programs\AVISynthPlus\plugins\DGDecode.dll")
MPEG2Source ("E:\_wrk\RinaTSDS\RinaNagai_TSDS-42048.d2v",cpu=5,moderate_h=45,moderate_v=55,info=2)
# if there are not MPEG2 artifacts and no ringing, set cpu=0
global rff=30000./1001.
vv=last
pics = cut(vv,1,06.598, 1,07.533)
global rff=60000./1001. # factor *2 for 60fps
tsl=int(2.0*rff/2.)+1 # duration of one pic
n=0
# noob hack for repeating each picture for half a second:
pics = Loop(pics,tsl,n+27,n+27)
pics = Loop(pics,tsl,n+26,n+26)
pics = Loop(pics,tsl,n+25,n+25)
pics = Loop(pics,tsl,n+24,n+24)
pics = Loop(pics,tsl,n+23,n+23)
pics = Loop(pics,tsl,n+22,n+22)
pics = Loop(pics,tsl,n+21,n+21)
pics = Loop(pics,tsl,n+20,n+20)
pics = Loop(pics,tsl,n+19,n+19)
pics = Loop(pics,tsl,n+18,n+18)
pics = Loop(pics,tsl,n+17,n+17)
pics = Loop(pics,tsl,n+16,n+16)
pics = Loop(pics,tsl,n+15,n+15)
pics = Loop(pics,tsl,n+14,n+14)
pics = Loop(pics,tsl,n+13,n+13)
pics = Loop(pics,tsl,n+12,n+12)
pics = Loop(pics,tsl,n+11,n+11)
pics = Loop(pics,tsl,n+10,n+10)
pics = Loop(pics,tsl,n+9,n+9)
pics = Loop(pics,tsl,n+8,n+8)
pics = Loop(pics,tsl,n+7,n+7)
pics = Loop(pics,tsl,n+6,n+6)
pics = Loop(pics,tsl,n+5,n+5)
pics = Loop(pics,tsl,n+4,n+4)
pics = Loop(pics,tsl,n+3,n+3)
pics = Loop(pics,tsl,n+2,n+2)
pics = Loop(pics,tsl,n+1,n+1)
pics = Loop(pics,tsl,n+0,n+0)
# -------- pre-blend kernels -------
C50d= "5 -3 13 -9 121 0 0 -0 -3 -25 0 0 -4 -0 27 0 0 0 0 -4 0 0 0 0 2" #C
C60 = "0 -0 0 0 112 0 0 -0 -0 -5 0 0 -0 -0 30 0 0 0 0 -3 0 0 0 0 8" #C
C61 = "0 -0 0 0 112 0 0 -0 0 -6 0 0 -0 -0 10 0 0 0 0 -3 0 0 0 0 0" #C
C62 = "0 -0 0 0 0 0 0 0 0 0 0 0 112 0 0 0 0 25 0 -0 0 0 -7 0 0" #C
C62a= "0 -0 0 0 0 0 0 0 0 0 0 0 112 0 0 0 0 17 0 -0 0 0 -4 0 0" #C
C62b= "0 -0 -7 0 0 0 0 25 0 0 0 0 112 0 0 0 0 0 0 -0 0 0 0 0 0" #C
C62c= "0 -0 -7 0 0 0 0 25 0 0 0 0 87 0 0 0 0 0 0 -0 0 0 0 0 0" #C
C62d= "0 -0 -2 0 0 0 0 9 0 0 0 0 140 0 0 0 0 17 0 -0 0 0 -3 0 0" #C
C63 = "0 -0 3 0 0 0 0 6 0 0 0 0 150 0 0 0 0 12 0 -0 0 0 3 0 0" #C
C64 = "0 -0 3 0 0 0 0 8 0 0 0 0 140 0 0 0 0 15 0 -0 0 0 3 0 0" #C
C64a= "0 -0 2 0 0 0 0 4 0 0 0 0 140 0 0 0 0 11 0 -0 0 0 3 0 0" #C
C65 = "0 -0 15 0 0 0 0 27 0 0 0 0 141 0 0 0 0 37 0 -0 0 0 27 0 0" #C
# C62a..d are examples that shift the pre-blending within the interlaced fields a bit up, or down, or both
# the purpose is to end up with less shimmering after yadif. also, it attempts to reduce the problem when
# interlaced program was sharpened field by field.
# C62b works quite often.
# The other kernels are less general and kind of worked with particular videos.
## ---------------------------------- do the pre-blend -----------------------------------
# --- switch on or off the following convolution and occasionally tweak kernel, according to results of deinterlacing.
# --- omit, if there is no interlacing.
CC=last
SeparateFields
ConvertToRGB32(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
GeneralConvolution(0, C62d) # select kernel to use, specify its variable name here
ConvertToYV12(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
Weave
MergeChroma(CC)
## ----------------------------- end of pre-blend convolution -------------
#-- Deinterlace Yadif -- delete this, when source is not actually interlaced i.e. shows combing without
Load_Stdcall_plugin("D:\Programs\AVISynthPlus\plugins\yadif.dll")
Yadif(mode=1,order=1)
AssumeFPS(60000,1001)
# -- after pre-blending and deinterlacing, we put together intro and still pictures.
vintro=cut(last,0,00.000, 1,06.582)
vmain=cut(last,1,08.000, 160,00.000)
#vintro = Yadif(vintro, mode=0,order=1)
#vintro = ChangeFPS(vintro,60000,1001)
#vmenu = ChangeFPS(vmenu,60000,1001)
pics=AssumeFPS(pics,60000,1001)
#last = pics + vintro + vmenu + vmain
last = vintro + pics + vmain # you need to edit the audio according to this
# -----
global rff=60000./1001. # factor *2 for 60fps
o=0
#------------------------------------------- end cutting -------------------------------
AddBorders(4,4,4,8,$7F7F7F)
#AddBorders( clip clip, int left, int top, int right, int bottom [, int color ] )
ConvertToRGB32(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
# default for this type of work: PC.709 = HDTV
# though most DVD = Rec601 !
# Rec.709 should be used when your source is HDTV (but fits some DVDs also)
# "Rec601" : Use 601 coefficients, scaled to TV range [16,235].
# "PC.601" : Use 601 coefficients, keep full range [0,255].
# -- symmetric kernels
C20 = "-2 0 3 0 -2 0 -1 -3 -1 0 2 -6 56 -6 2 0 -1 -3 -1 0 -1 0 3 0 -1"
C21 = "-1 0 3 0 -1 0 -1 -3 -1 0 3 -5 56 -5 3 0 -1 -3 -1 0 -1 0 3 0 -1"
C22 = "-1 0 3 0 -1 0 -1 -3 -1 0 3 -6 48 -6 3 0 -1 -3 -1 0 -1 0 3 0 -1"
C23 = "-1 0 3 0 -1 0 -1 -3 -1 0 3 -5 48 -5 3 0 -1 -3 -1 0 -1 0 3 0 -1"
C24 = " 0 0 3 0 -0 0 -1 -3 -1 0 4 -4 44 -4 4 0 -1 -3 -1 0 0 0 3 0 0"
# -- asymmetric kernels
# -- select one of these kernels, ordered by increasing radius and impact:
# C3.1 will do for most good quality DVDs with sufficient sharpness
C000 = "0 0 0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" #dummy for asymmetric (to keep the shifting)
C31 = "3 -4 8 -10 112 0 0 -0 -4 -15 0 0 -6 -0 15 0 0 0 0 -5 0 0 0 0 0" #C3.1
C32 = "3 -3 9 -13 112 0 0 -0 -4 -15 0 0 -6 -0 15 0 0 0 0 -5 0 0 0 0 0" #C3.2
C32a = "3 -3 9 -13 140 0 0 -0 -4 -15 0 0 -6 -0 15 0 0 0 0 -5 0 0 0 0 0" #C3.2a
C32c = "3 -3 11 -13 173 0 0 -0 -4 -10 0 0 -6 -0 15 0 0 0 0 -5 0 0 0 0 0" #C3.2c
C33 = "3 -3 10 -15 112 0 0 -0 -4 -12 0 0 -6 -0 14 0 0 0 0 -4 0 0 0 0 0" #C3.3
C331 = "4 -5 14 -15 112 0 0 -0 -4 -12 0 0 -6 -0 14 0 0 0 0 -4 0 0 0 0 0" #C3.31
C333 = "3 -5 17 -21 112 0 0 -0 -4 -13 0 0 -6 -0 14 0 0 0 0 -4 0 0 0 0 0" #C3.33
C335 = "3 -5 15 -21 112 0 0 1 -4 -13 0 0 -6 3 14 0 0 0 0 -4 0 0 0 0 0" #C3.33
C34 = "2 -5 12 -20 112 0 0 -0 -4 -10 0 0 -6 -0 12 0 0 0 -1 -3 0 0 0 0 1" #C3.4
C40 = "3 -5 17 -21 112 0 0 -0 -4 -13 0 0 -6 -0 15 0 0 0 0 -4 0 0 0 0 0" #C4.0
C40a = "3 -5 21 -23 112 0 0 -0 -4 -12 0 0 -8 -0 14 0 0 0 0 -4 0 0 0 0 0" #C4.0a
C40a1= "3 -9 21 -17 112 0 0 0 -4 -12 0 0 -8 -0 14 0 0 0 0 -4 0 0 0 0 0" #
C40a2= "3 -5 21 -17 112 0 0 2 -4 -12 0 0 -8 4 10 0 0 0 -1 -4 0 0 0 0 2" #
C40g ="5 -11 29 -25 130 0 0 -0 -3 -10 0 0 -5 -0 20 0 0 0 0 -6 0 0 0 0 2" #C4.0g
C40h ="5 -11 29 -25 130 0 0 -0 -3 -30 0 0 -5 -0 40 0 0 0 0 -8 0 0 0 0 3" #C4.0h
C40i ="3 -9 25 -25 130 0 0 2 -4 -25 0 0 -5 5 25 0 0 0 -1 -7 0 0 0 0 3" #C4.0i #######
C40i1="3 -9 25 -25 130 0 0 2 -4 -25 0 0 -5 5 15 0 0 0 -1 -7 0 0 0 0 3"
C40i2="3 -9 25 -25 130 0 0 2 -4 -41 0 0 -5 5 13 0 0 0 -1 -7 0 0 0 0 3" #
C40k ="3 -10 23 -28 123 0 0 2 -4 -25 0 0 -5 5 25 0 0 0 -1 -7 0 0 0 0 3" #C4.0k
C40k1="3 -10 25 -28 132 0 0 2 -4 -27 0 0 -5 5 23 0 0 0 -1 -7 0 0 0 0 3" #C4.0k1 #########
C40k2="3 -10 23 -31 119 0 0 2 -4 -25 0 0 -5 5 15 0 0 0 -1 -7 0 0 0 0 3" #C4.0k2
C40k3="3 -9 25 -31 131 0 0 2 -4 -27 0 0 -5 5 23 0 0 0 -1 -11 0 0 0 0 3" #C4.0k3
C40k4="3 -13 13 -31 123 0 0 2 -4 -31 0 0 -5 5 23 0 0 0 -1 -11 0 0 0 0 3" #C4.0k4
C40k5="3 -11 10 -31 123 0 0 2 -4 -31 0 0 -5 5 23 0 0 0 -1 -13 0 0 0 0 3" #C4.0k5
C40k6 ="4 -17 17 -27 137 0 0 2 -4 -31 0 0 -5 5 23 0 0 0 -1 -11 0 0 0 0 3" #C4.0k6
C40k7b="2 -5 17 -27 137 0 0 2 -5 -31 0 0 -4 4 27 0 0 0 -1 -9 0 0 0 0 3" #C4.0k7b ################
C40k7a="4 -7 17 -27 113 0 0 2 -4 -37 0 0 -5 5 27 0 0 0 -1 -11 0 0 0 0 3" #C4.0k7a ########
C40k8 ="3 -11 19 -37 89 0 0 2 -4 -13 0 0 -5 5 9 0 0 0 -1 -11 0 0 0 0 1" #C4.0k8 ##### if super blurred
C40k8a="3 -7 19 -37 89 0 0 2 -4 -13 0 0 -5 5 9 0 0 0 -1 -7 0 0 0 0 1" #C4.0k8a
C40k9 ="1 -7 11 -29 89 0 0 2 -4 -21 0 0 -5 5 21 0 0 0 -1 -7 0 0 0 0 3" #C4.0k9 ########
# C40 group has strong halo softening and anti-ringing compensation, but only for DVDs that have correct bandwidth limiting.
# on pixel-sharp and high-contrast vertical lines it will still show a ringing pattern.
# Use C40 for sources that would look awkwardly blurred after the reencoding, when they won't allow
# the stronger sharpening by the other kernels because of noise, grainy lines, and sharp halos/outlines.
C50 = "4 -4 6 -3 121 0 0 -0 -2 -25 0 0 -4 -0 30 0 0 0 0 -7 0 0 0 0 5" #C5.0 strong dehalo
C50b = "3 -5 3 -4 121 0 0 -0 -3 -15 0 0 -4 -0 15 0 0 0 0 -4 0 0 0 0 0" #C5.0b
C50d= "5 -3 13 -9 121 0 0 -0 -3 -25 0 0 -4 -0 27 0 0 0 0 -4 0 0 0 0 2" #
C50g = "2 -8 14 -7 121 0 0 -0 -3 -10 0 0 -4 -0 1 0 0 0 0 -1 0 0 0 0 7" #
C50g1= "2 -8 14 -7 121 0 0 2 -4 -15 0 0 -4 4 11 0 0 0 -1 -5 0 0 0 0 2" #C5.0g1
C50g1a="2 -8 14 -7 121 0 0 2 -4 -21 0 0 -4 4 17 0 0 0 -1 -5 0 0 0 0 2" #C
C50g2= "2 -5 14 -7 121 0 0 2 -4 -15 0 0 -4 4 17 0 0 0 -1 -5 0 0 0 0 2" #C
C50g3= "2 -7 17 -3 121 0 0 2 -4 -15 0 0 -4 4 19 0 0 0 -1 -5 0 0 0 0 5" #C
C50g4= "2 -7 17 -3 121 0 0 2 -4 -12 0 0 -4 4 25 0 0 0 -1 -7 0 0 0 0 7" #C
C50g4a="2 -7 17 -3 121 0 0 2 -4 -17 0 0 -4 4 23 0 0 0 -1 -7 0 0 0 0 5" #C5.0g4a RinaH_TSDS-40277
C50g5= "3 -15 19 -1 121 0 0 2 -4 -1 0 0 -4 4 23 0 0 0 -1 -19 0 0 0 0 1" #C5.0g5
C50g5a="3 -15 19 -1 121 0 0 2 -4 -12 0 0 -4 4 23 0 0 0 -1 -7 0 0 0 0 1" #C5.0g5a
C50g5b="2 -15 23 -3 121 0 0 2 -5 -31 0 0 -4 4 37 0 0 0 -0 -3 0 0 0 0 6" #C5.0g5b ## strong dehalo
C50g5c="1 -11 19 -9 113 0 0 2 -5 -21 0 0 -4 4 11 0 0 -0 -1 -7 0 0 0 0 3" #C5.0g5c ########
C50g5d="1 -11 19 -9 113 0 0 2 -5 -31 0 0 -4 4 23 0 0 -0 -1 -9 0 0 0 0 5" #C5.0g5d ########
C50g5e="1 -11 19 -9 113 0 0 2 -5 -17 0 0 -4 4 3 0 0 -0 -1 -3 0 0 0 0 1" #C5.0g5e
C50g5f="1 -11 19 -9 113 0 0 2 -5 -17 0 0 -4 3 17 0 0 -0 -1 -5 0 0 0 0 5" #C5.0g5f
# Use C50 kernels if there is strong ringing plus outlining.
GeneralConvolution(0, C50g5f) # select kernel to use, specify its variable name here
ConvertToYV12(matrix="PC.709",interlaced=false,chromaresample="lanczos4")
#AssumeFPS(60000,1001)
CShft(last,-0.3,-0.66) # correct chroma shift
Crop(0,6,-2,-2)
#Crop(clip clip, int left, int top, int -right, int -bottom [, bool align ] )
### ---- we are ready for output to Avidemux or some other encoder.
# ---- (should denoise, upsize, and sharpen strongly on upsized format).
#--------------------------- helper funcs ---------------------------------------
function CShft(clip In, float X, float Y) {
w = In.Width()
h = In.Height()
Tmp = In.BlackmanResize(w, h, -X, -Y, w-X, h-Y, 5)
In = MergeChroma(In, Tmp)
return In}
function cut(clip In, int Mins, float secs, int Mins2, float secs2) {
tpos = 60.*Mins + secs
te = 60.*Mins2 + secs2
Outclp=Trim(In,int(rff*tpos)+1,-int(rff*(te-tpos))-1)
return Outclp}