gwendolien
19th August 2013, 20:39
Thanks for the swift response neuron2.
# BECK_RECONSTRUCTIE_C.AVS
LoadPlugin("C:\AV_Stuff\Video\Avisynth\Plugins\RT_Stats26.dll")
LoadPlugin("C:\AV_Stuff\Video\Avisynth\Plugins\GrunT.dll")
LoadPlugin("C:\AV_Stuff\Video\Avisynth\Plugins\GScript.dll")
SetMemoryMax(448)
SetMTMode(2,5)
dvd_t=AviSource("G:\DVD_Deinterlaced_Cropped.avi")#.ConvertToYV12#
SetMTMode(2)
Global dvd=dvd_t.ConvertToRGB24().Crop(1, 0, 700, 494).ConvertToYV12
SetMTMode(2,5)
vhs_t=AviSource("G:\VHS_Deinterlaced_Cropped.avi").ConvertToYV12#.ColorYUV(Levels="PC->TV")#SOURCE is YUY2
SetMTMode(2)
vhs_t=vhs_t.Lanczos4Resize([<"Wf", 760, 790, 776>],[<"Hf", 480, 510, 494>])
bg=BlankClip(vhs_t, Length=vhs_t.FrameCount, Width=870, Height=508, color=$000000)
vhs_u=bg.Overlay(vhs_t, opacity=1.0, x=[<"Xc", 0, 28, 17>], y=[<"Yc", -10, 10, 7>])#.ConvertToYV12(matrix="PC.709")# OVERLAY OUTPUT RGB32
vhs_v=vhs_u.Crop(14, 4, 776, 494)#.ColorYUV(off_y=6, gain_y= 50, cont_y=110, off_u=-0, cont_u=100, off_v=-1, cont_v=6)
dvdL=dvd.Crop(0, 0, 34, 0)
dvdR=dvd.Crop(dvd.Width-42, 0, 0, 0)
dvdvhs=StackHorizontal(dvdL, dvd, dvdR)
vhs_w=vhs_v.HistogramAdjustRGB(dvdvhs)
Global vhsfull=vhs_w.Overlay(dvd.Crop(100, 394, 500, 70), opacity=1.0, x=132, y= 394)
Global vhsdvd=vhsfull.Crop(32, 0, 700, 494)
vhs_replace=vhsfull # vhsfull / vhsfull0 / vhsfull1 / vhsfull2 / vhsfull3
vhs_replace_a=vhs_replace.Tweak(Bright=-0, Hue=-0, Cont=1.0, Coring=false)#.RGBAdjust_gwe(6, -9, 0) # LEFT side version
vhs_replace_b=vhs_replace.Tweak(Bright= 5, Hue=0, Cont=1.0, Coring=false)#.RGBAdjust_gwe(6, -9, 0) # RIGHT side version
vhsfullmaskright=GraMaMa(vhsfull, mode=4, a=0, rad=vhsfull.Width).ConvertToRGB32
Global vhs_corr=Overlay(vhs_replace_a, vhs_replace_b, 0, 0, Mask=vhsfullmaskright) # GRADUALLY CHANGE FORM VHS_REPLACE_A @ LEFT TO VHS_REPLACE_B AT RIGHT
Global vhs_aligned=ScriptClip(vhs_corr, """LumaCorrelation(vhsdvd, dvd, 7, 11, 32)""")# for aligning the VHS to the DVD
# CREËER DE BENODIGDE MASKERS VOOR HET VLOEIEND LATEN OVERLOPEN VAN HET VHS MATERIAAL NAAR HET DVD MATERIAAL
leftwidth=Ceil(vhsfull.Width/4)+Int((vhsfull.Width+1)/4)
rightwidth=vhsfull.Width-leftwidth
br=4*[<"Breedte", 1, 26, 10>]
maskleft1=GraMaMa(vhsfull.Crop(0, 0, 400+br, 0, align=true), mode=4, a=30+int(0.80*(br)), b=494, rad=br).Levels(16, 1, 235, 0, 255, coring=false)
left=BlankClip(maskleft1, Width=600, color=$000000)
maskleft=maskleft1.Overlay(left, opacity=1.0, x=30+int(0.80*br)).Crop(0, 0, leftwidth, 0, align=true)
maskright1=GraMaMa(vhsfull.Crop(378-br, 0, 392+br, 0, align=true), mode=4, a=342-int(0.85*br), b=494, rad=br).Levels(16, 1, 235, 0, 255, coring=false)
right=BlankClip(maskright1, Width=342-2*int(0.425*br), color=$000000)
maskright=maskright1.Overlay(right, opacity=1.0, x=0).Crop(0, 0, vhsfull.Width-leftwidth, 0, align=true)
maskfull=StackHorizontal(maskleft,maskright).Levels(16, 1, 235, 0, 255, coring=false)#.IsFormat
vhs_left=vhs_aligned.Crop(0, 0, 34, 0, align=true)# VHS aligned to DVD
vhs_right=vhs_aligned.Crop(734, 0, 0, 0, align=true)# VHS aligned to DVD
# GENERATE FINALLY THE OUTPUT.....
rslt0=vhs_aligned.Overlay(dvd, Mask=MaskFull.Invert.Crop(32, 0, -44, 0), x=37)# for VHS2DVD alignment
#rslt0=vhs_aligned.Overlay(vhs_corr, Mask=MaskFull, x=0)# for VHS2DVD alignment
return rslt0
#=================================================================================================================================================
Function IsFormat(clip c)
{
text=IsYV12(c)?"YV12":ISYUY2(c)?"YUY2":IsRGB24(c)?"RGB24":IsRGB32(c)?"RGB32":"other"
return Subtitle(c, text+"\n"+String(c.Width)+"x"+String(c.Height), size=13, y=c.height-26, lsp=0)
}
#==============================================================================================================================================
Function LumaCorrelation(clip clip0, clip clip1, clip clip2, int radX, int radY, int off)
{
Width1=clip0.Width()
Height1=clip0.Height()
clipz=clip0.Lanczos4Resize(2*Width1, 2*Height1)
X=2*radX
Y=2*radY
W=-2*radX
H=-2*radY
BestX=255
BestY=255
diff=0
n=current_frame
S=""
clipa=clip1.Lanczos4resize(2*clip1.Width, 2*clip1.Height)
clipb=clip2.Lanczos4resize(2*clip2.Width, 2*clip2.Height)
start=RT_Timer()
GScript("""
for (i=-radX, radX, 1){
for (j=-radY, radY, 1){
tdiff=RT_LumaCorrelation(clipa, clipb, n=n, x=X, y=Y, w=W, h=H, n2=n, x2=X+i, y2=Y+j, interlaced=false)
if(tdiff>diff){
diff=tdiff
BestX=i
BestY=j
}
# WriteFileStart(clip0, "LumaDiff.txt", String(i)+" / "+String(j)+" | "+String(diff), append=true)
}#j=j+1 loop
S=S+"\n"
}#i=i+1 loop
""")
end=RT_Timer()
duration=String(end-start,"%.2f")
bg=clipz.BlankClip(Length=clipz.FrameCount, color=Color_Black)
result=bg.Overlay(clipz, x=BestX, y=BestY, opacity=1.0).Bicubicresize(Width1, height1)# for VHS2DVD alignment
#result=clipz.Overlay(clipb, x=2*off-BestX, y=-BestY, opacity=1.0).BicubicResize(Width1, height1)# for DVD2VHS alignemnt
#WriteFileStart(clipz, "Beck_analysis.txt", String(n), """ ";" """, String(BestX), """ ";" """, String(BestY), """ ";" """, String(diff), append=true)
return result # FOR REAL OUTPUT
return result.Subtitle("X="+String(BestX)+"\nY="+String(BestY)+"\n"+String(diff)+"\n"+duration, x=30, size=15, lsp=0)#FOR DEBUGGING
}
#===========================================================================================================================================================
Function HistogramAdjustRGB(clip clip1, clip clip2)
{
clipared=clip1.ConvertToRGB24.ShowRed("YV12")
clipagreen=clip1.ConvertToRGB24.ShowGreen("YV12")
clipablue=clip1.ConvertToRGB24.ShowBlue("YV12")
Global clipbred=clip2.ConvertToRGB24.ShowRed("YV12")
Global clipbgreen=clip2.ConvertToRGB24.ShowGreen("YV12")
Global clipbblue=clip2.ConvertToRGB24.ShowBlue("YV12")
cliprsltred=clipared.ScriptClip("""HistogramAdjust(type="match", mclip=clipbred, mf=current_frame)""")
cliprsltgreen=clipagreen.ScriptClip("""HistogramAdjust(type="match", mclip=clipbgreen, mf=current_frame)""")
cliprsltblue=clipablue.ScriptClip("""HistogramAdjust(type="match", mclip=clipbblue, mf=current_frame)""")
return MergeRGB(cliprsltred, cliprsltgreen, cliprsltblue).ConvertToYV12#(Matrix="PC.709")
}
I tested also with VFAPI and just "video output", not the VFAPI codec.
The script is loaded properly, but the output size seems to be limited ther to 4GB file size. The processing continues for a while, with the filesize staying constant at 4GB....
Don't know what the final outcome will be, the whole clip takes about 13 hours(estimated)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.