digitalFAQ.com Forum

digitalFAQ.com Forum (https://www.digitalfaq.com/forum/)
-   Restore, Filter, Improve Quality (https://www.digitalfaq.com/forum/video-restore/)
-   -   Frame-by-frame vertical jitter removal for interlaced video? (https://www.digitalfaq.com/forum/video-restore/12635-frame-frame-vertical.html)

traal 03-19-2022 10:50 PM

Frame-by-frame vertical jitter removal for interlaced video?
 
1 Attachment(s)
My VHS captures have occasional vertical jitter, I believe the problem to be a weak "start of frame" signal from the VCR causing the capture card to delay the start of frame for a line or two. So I wrote an AviSynth function that lets you manually correct these glitches, frame by frame:

Code:

function MoveFieldDownAndBackfill(clip c, int numRows) {
        c
        line1=Crop(0,0,-1,numRows)
        Crop(0,0,-0,-numRows)
        AddBorders(0,numRows,0,0)
        Overlay(last, line1, mode="blend", x=0, y=0)
        return last
}

function ShiftFieldsDownAndBackfill(clip c, int frameNumber, int r0_offset, int r1_offset) {
        c
        SeparateFields()
        ApplyRange(frameNumber*2, frameNumber*2, "MoveFieldDownAndBackfill", r0_offset)
        ApplyRange(frameNumber*2+1, frameNumber*2+1, "MoveFieldDownAndBackfill", r1_offset)
        Weave()
}

MoveFieldDownAndBackfill is just a helper function. Call ShiftFieldsDownAndBackfill with the number of lines you want to shift the odd fields down, and the number of lines you want to shift the even fields down, and it fixes that frame. For example:

Code:

ShiftFieldsDownAndBackfill(6,0,1)
This takes frame #6, shifts the even fields down by 0 lines, and the odd fields down by 1 line, and backfills the top of the frame with a duplicate of the top line of the top field(s) you just shifted down. So it replaces a whole-frame glitch with an almost unnoticeable top-of-the-frame glitch.

Sometimes you will need to shift both fields down by up to 2 lines each.

This code is very inefficient, and locating the glitched frames is a manual process, so it's best not to use this on more than a couple of dozen glitches in a video file. But it stabilizes the frame pretty well without resorting to brute force like using something like stab(). I've attached a restored jitter clip that was posted in this thread.

Also, another useful thing to do is call FreezeFrame() when the image is static. For example:

Code:

FreezeFrame(2,10,7)
This duplicates "good" frame 7 across "bad" frames 2 through 10.

traal 03-20-2022 11:42 AM

1 Attachment(s)
Negative numbers will now move the field up. Only one function changed:

Code:

function MoveFieldDownAndBackfill(clip c, int numRows) {
        c
        if(numRows < 0) { # moving up
                numRows = -numRows
                line1=Crop(0,(c.Height-1)-numRows,-0,numRows)
                Crop(0,1,-0,c.Height-numRows)
                AddBorders(0,0,0,numRows)
                Overlay(last, line1, mode="blend", x=0, y=c.Height-1)
        }
        else if(numRows > 0) { # moving down
                line1=Crop(0,0,-0,numRows)
                Crop(0,0,-0,-numRows)
                AddBorders(0,numRows,0,0)
                Overlay(last, line1, mode="blend", x=0, y=0)
        }
        return last
}


traal 07-24-2022 07:00 PM

To check my work, I like to put the following line into a 2nd .avs file that loads the first:

Code:

clip = AviSource("MyVideo.avs")
clip.AssumeTFF()
Subtract(clip, clip.Trim(1, 0))

It makes glitches much easier to see with tired eyes.

I also use FreezeFrame to fix some timebase errors, and occasionally JDL_FreezeRegion when the error is only in part of the frame with little movement.


All times are GMT -5. The time now is 07:41 PM

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.