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.

lordsmurf 01-11-2025 11:34 PM

I can't believe that I've had this bookmarked for almost 3 years now. I have a project where I want to try this, but it just never happened.

Aya_Rei 02-05-2025 12:38 AM

Quote:

Originally Posted by lordsmurf (Post 100733)
I can't believe that I've had this bookmarked for almost 3 years now. I have a project where I want to try this, but it just never happened.

The script is pretty useful, and I'm glad it exists as I've used it myself. Especially because usually I've seen only one field of a given frame be offset by one pixel (sometimes two pixels, rarely three and four), very easy to correct and since I'd be cropping some pixels from the top and bottom anyway, no defects are detected. Of course, most time consuming part is locating the frames.

You probably already know this but for anyone wanting a tip, the second number set in the script (first is the number of the frame you want to be adjusted) represents the bottom field and the third number set represents the top field. Use the remove top/keep bottom field & remove bottom/keep top field deinterlace options in VirtualDub to check which field has the offending pixel offset that'll need to be corrected.


All times are GMT -5. The time now is 01:05 PM

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