Log in

View Full Version : VHS Horizontal Lines: ReplaceFrameAvg()


AviUser
29th October 2013, 03:01
Hello,

[Similar topic with no solution] (http://forum.videohelp.com/threads/329131-Advanced-Restoration-Removing-tracking-lines-from-Video?p=2039766#post2039766)
So I have a video sourced from VHS tape recorded in a TV studio. Every minute or so, for 1-5 frames, horizontal white lines appear on the clip and distort the image in those places.
What I have been doing is DeleteFrame() on each of these, until I realized that this does not sync audio, so I defined:
function DeleteFrame2(clip clp, int framenumber) {
return clp.trim(0,framenumber-1) + clp.trim(framenumber+1,0)
}

However, this causes gaps in the audio.

I was thinking it would be ideal if I could somehow repair these with a ReplaceFrameAvg() function, which takes the average of the frame before and the frame after.

Any ideas?

Gavino
29th October 2013, 13:49
A simpler solution would be just to use FreezeFrame (http://avisynth.nl/index.php/FreezeFrame)().

However, your request could be done as follows:
function ReplaceFrameAvg(clip c, int f) {
# Note: assumes 0 < f < frameCount-1
avg = Merge(c.SelectEvery(1,-1), c.SelectEvery(1,1))
c.Trim(0, -f) + avg.Trim(f, -1) + c.Trim(f+1, 0)
AudioDub(c) # preserve audio
}

If there are many frames to be replaced, then rather than multiple function calls, it would be more efficient to call Merge() once, do the Trims manually, and do a single AudioDub() after all replacements have been done.

Evil_Burrito
30th October 2013, 18:21
Yes AviUser, there are hundreds ways to what you want. As Gavino mentioned freezeframe is one method. You could also delete the bad frame, then duplicate the previous one. If you don't want to spend so much time manually checking frames, you could use a temporal denoiser. Or even better, you could use a motion compensated temporal denoiser. Or you could learn how to use the DeScratch/DeSpot filters in combination with DePanEstimate (or mvtools). Although DeScratch/DeSpot results may vary because the settings can be difficult to configure.

AviUser
31st October 2013, 17:06
Thank you everyone for your help!
This solves my problem.

AviUser
9th November 2013, 23:01
Just to let you know the results when I applied your tips to a real video:
1. ReplaceFrameAvg() is the best, except causes ghost-like effects when there is movement and doesn't work when there are horizontal lines in two consecutive frames
2. I prefer FreezeFrame() over DeleteFrame2() because no audio blips will be introduced and it won't really increase the size of the video (identical frames compress well)
:thanks: