tsp
19th August 2004, 18:41
I wrote a filter to fix some of the vertical sync problem in vhs video capture. It uses the autocrop filter and requires the video to have a black border.
it uses the following syntax
vsync(clip,the framenumber to get the height of the topborder)
function vsync(clip a,int calibrateframenumber)
{
cf=a.trim(calibrateframenumber,10).pointresize(a.width,a.height*4)
global topbarheight = (cf.height/2 - cf.crop(0,0,10,cf.height/2).autocrop(mode=0,wMultOf=4 ,threshold=20).height)/4
#global bottombarheight = (cf.height/2 - cf.crop(0,cf.height/2,10,cf.height/2).autocrop(mode=0,wMultOf=4 ,threshold=20).height)/4
global fillborder = cf.pointresize(a.width,topbarheight*4,0,0,topbarheight,cf.width)
top=a.crop(0,topbarheight-4,a.width,4)
conditionalFilter(top,jittercorrect(a), a, "AverageLuma()", ">", "20")
function jittercorrect(clip c)
{
c=c.pointresize(c.width,c.height*4) #*4 yv12 resize
global c=c
c=ScriptClip(c,"vmove(c,
\4*topbarheight - c.height/2 + c.crop(0,0,c.width,c.height/2).trim(current_frame,-1).autocrop(mode=0,wMultOf=4 ,threshold=20).height \
)")
#c=ScriptClip(c,"vmove(c,
#\ c.height/2 -4*bottombarheight - c.crop(0,c.height/2,10,c.height/2).trim(current_frame,-1).autocrop(mode=0,wMultOf=4 ,threshold=20).height \
#)")
return c.verticalreduceby2().verticalreduceby2()
}
function vmove(clip cl, int offset)
{
offs = offset+4
topborder= fillborder.bilinearResize(cl.width,offs,0,0,cl.width,8)
tempclip=stackvertical(topborder,cl)
return tempclip.crop(0,4,cl.width,cl.height)
}
}
it uses the following syntax
vsync(clip,the framenumber to get the height of the topborder)
function vsync(clip a,int calibrateframenumber)
{
cf=a.trim(calibrateframenumber,10).pointresize(a.width,a.height*4)
global topbarheight = (cf.height/2 - cf.crop(0,0,10,cf.height/2).autocrop(mode=0,wMultOf=4 ,threshold=20).height)/4
#global bottombarheight = (cf.height/2 - cf.crop(0,cf.height/2,10,cf.height/2).autocrop(mode=0,wMultOf=4 ,threshold=20).height)/4
global fillborder = cf.pointresize(a.width,topbarheight*4,0,0,topbarheight,cf.width)
top=a.crop(0,topbarheight-4,a.width,4)
conditionalFilter(top,jittercorrect(a), a, "AverageLuma()", ">", "20")
function jittercorrect(clip c)
{
c=c.pointresize(c.width,c.height*4) #*4 yv12 resize
global c=c
c=ScriptClip(c,"vmove(c,
\4*topbarheight - c.height/2 + c.crop(0,0,c.width,c.height/2).trim(current_frame,-1).autocrop(mode=0,wMultOf=4 ,threshold=20).height \
)")
#c=ScriptClip(c,"vmove(c,
#\ c.height/2 -4*bottombarheight - c.crop(0,c.height/2,10,c.height/2).trim(current_frame,-1).autocrop(mode=0,wMultOf=4 ,threshold=20).height \
#)")
return c.verticalreduceby2().verticalreduceby2()
}
function vmove(clip cl, int offset)
{
offs = offset+4
topborder= fillborder.bilinearResize(cl.width,offs,0,0,cl.width,8)
tempclip=stackvertical(topborder,cl)
return tempclip.crop(0,4,cl.width,cl.height)
}
}