Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th August 2008, 19:54   #1  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
occasional displaced fields

I have a terrible source captured from 10+ year old VHS, that was created with an old video camera (true interlaced NTSC). I used ffdshow to encode it in Huffyuv YV12. I would like to turn it into something semi watchable. This is a friends home video I'm helping him out with, but I don't know that much, just what I've learned from lurking here for a long time. Processing time is no object; I just want to get the best end result possible.

I know I have to SeparateFields and process even and odd separately (I think I'll keep it interlaced because said friend will eventually use this as raw video for editing and will probably put it on DVDs as gifts to friends and family).

The first hurdle that has me scratching my head is every few seconds, one of the fields is displaced downward four or five lines. Does anyone know how to correct this? That's priority one.

Also, the color and balance of this video are all over the place. Is there a plugin that can automagically even it out?

I'm sure I'll be asking more, but that's enough for me to start with. I will probably be working with intermediate files on this one, fixing one thing at a time, and reencoding to Huffyuv at each step.

EDIT: It's worse than I thought. In at least one place, there are 15 frames in a row with fields displaced downward, and the amount of displacement isn't consistent at all. Could I use some sort of global motion compensation for this, like depan, for vertical motion only with minimal side effect to actual camera panning. I haven't actually tried depan, but I have tried the deshaker for vdub, and I found the side effects to be very distracting. I should also mention that either the tracking is off on my VCR, or else there was garbage introduced somewhere else along the way so that there's a band of really bad noise at the bottom of the frame. I assume I'll have to cut this off before doing any motion analysis, right? Can I analyse a clip with a smaller vertical dimension and apply global motion comp. to the full sized clip?

Last edited by 4evrplan; 19th August 2008 at 20:20.
4evrplan is offline   Reply With Quote
Old 19th August 2008, 22:21   #2  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
I just tried the MVDepan/DepanStabilize combo. with no luck. I tried analysing a version of the clip with the garbage cropped off of the bottom as well and applying the stabilize to the original, but that worked no better. Here's my script.

AVISource("Recital.avi")
source=last.AssumeTFF()
cropped=source.Crop(0,0,0,-136)
source=source.SeparateFields()
cropped=cropped.SeparateFields()
vectors=cropped.MVAnalyse(isb=false)
globalmotion=cropped.MVDepan(vectors,pixaspect=0.911,thSCD1=400)
DepanStabilize(source,data=globalmotion,cutoff=2.0,mirror=15,pixaspect=0.911)
Weave()

Does MVTools concentrate on horizontal panning, with less aggressive vertical compensation? If so, perhaps I'd have better luck rotating the clip 90 degrees, compensating, and rotating back. I don't really understand the different color formats though, except for RGB. Since my clip is in YV12, will rotating mess up the color format?
4evrplan is offline   Reply With Quote
Old 20th August 2008, 14:53   #3  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
I just tried the TurnLeft - process - TurnRight trick, and the result is even worse than the original (but it didn't mess up the color). Before you could tell it was just the video messing up. Now it seems like there's really bad vertical panning, and the motion is sort of rubbery. I've created a function, "bump" that allows me to bump a frame up (and since I use SeparateFields, I can bump a field). Depending on how many there are, I might be willing to process each of the bad fields manually. Does anybody know a way to identify these fields automatically? If I can identify them, I can step through the video one bad field at a time and adjust the offset. It's probably going to be too many to do this way, but I'm just thinking.
4evrplan is offline   Reply With Quote
Old 20th August 2008, 21:15   #4  |  Link
QuaddiMM
Registered User
 
Join Date: May 2008
Posts: 10
Is the displacement in the original video file (try open directly without avisynth) or only with avisynth?
What version of avisynth? -> Try 2.58 RC3

Is it this error: http://forum.doom9.org/showthread.php?t=138391 ?
QuaddiMM is offline   Reply With Quote
Old 20th August 2008, 22:35   #5  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
Unfortunately, the problems is still there when I play the video directly rather than using Avisynth. I'm working on a function which uses ConditionalFilter to detect frames with this problem and shift them up by an appropriate amount. I've written several versions because it would correct some frames and not other. Additionally, a few versions shifted frames that did not need correction. The current version is supposed to detect the edge between the blank area at the top of a shifted frame and the actual frame using RGBDifference(), but this version has stopped working all together. Here's the line I think is to blame.

inc = ConditionalFilter(inc,inc.Crop(0,22,0,0).Addborders(0,0,0,22),inc,"RGBDifference(ConvertToRGB().Crop(0,21,0,-218),ConvertToRGB().Crop(0,22,0,-217))","greaterthan","0.03")

I have several similar lines in the script to correct different amounts of shift. This one is for a 22 line shift. My test frame is shifted by 22 lines, but this script fails to correct it. And in case you're wondering why I'm doing an intermediate conversion to RGB and using RGBDifference() instead of AverageLuma(), it's so I can create test clips that are a single scan line tall.
4evrplan is offline   Reply With Quote
Old 20th August 2008, 22:52   #6  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
Nevermind. I just forgot to return the clip in the function. Chalk it up to inexperience.
4evrplan is offline   Reply With Quote
Old 21st August 2008, 16:30   #7  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
Here's the code I came up with to correct this.

function BumpEven(clip inc, int offset, float thresh)
{
inc = ConditionalFilter(inc,inc.Crop(0,offset,0,0).AddBorders(0,0,0,offset),inc,"RGBDifference(ConvertToRGB().Crop(0," + String(offset) + "-1,0," + String(offset) + "-240),ConvertToRGB().Crop(0," + String(offset) + ",0," + String(offset) + "-239))","greaterthan",String(thresh))
return (offset > 1) ? BumpOdd(inc, offset-1, thresh) : inc
}

function BumpOdd(clip inc, int offset, float thresh)
{
inc = ConditionalFilter(inc,inc.ConvertToRGB().Crop(0,offset,0,0).AddBorders(0,0,0,offset).ConvertToYV12(),inc,"RGBDifference(ConvertToRGB().Crop(0," + String(offset) + "-1,0," + String(offset) + "-240),ConvertToRGB().Crop(0," + String(offset) + ",0," + String(offset) + "-239))","greaterthan",String(thresh))
return (offset > 1) ? BumpEven(inc, offset-1, thresh) : inc
}

function Bump(clip inc, int maxOffset, float thresh)
{
Assert(maxOffset > 0)
inc = (maxOffset % 2 == 0) ? BumpEven(inc, maxOffset, thresh) : BumpOdd(inc, maxOffset, thresh)
return inc
}

It's sloppy, slow, and not generalized at all, but it corrects over half of the shifted frames without damaging good ones, depending on the threshold value. However, after seeing several consecutive shifted frames in their corrected positions, I realized that they're all dropped frames. It's an old tape, so maybe the VCR dropped the frames, but I have a feeling it was the horrible video camera used to record it in the first place.

That opens a whole new can of worms. I would like to use mvtools to replace these bad frames with interpolated frames, but is there a way to automatically detect and replace dropped frames with interpolated frames? The issue is complicated by the fact that dropped frames are not identical to previous frames (shifted + noise). Ahrrrgh! Someone please help.
4evrplan is offline   Reply With Quote
Old 22nd August 2008, 18:22   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
It's probably of little consolation to you, and doesn't solve your main problem, but you could at least make the ConditionalFilter coding more user-friendly by using GRunT's version.

By using the args parameter, you don't need to build up the string dynamically in order to use the values of offset and thresh. For example, you could write
Code:
inc = ConditionalFilter(inc, inc.Crop(0,offset,0,0).AddBorders(0,0,0,offset), inc,
\      "RGBDifference(ConvertToRGB().Crop(0,offset-1,0,offset-240),
\                     ConvertToRGB().Crop(0,offset,0,offset-239)) > thresh",
\     args="offset, thresh")
EDIT: now that I see it written more clearly, I can also see that it can be speeded up by doing the conversions and crops outside the conditional, hence
Code:
incRGB = inc.ConvertToRGB()
c1 = incRGB.Crop(0,offset-1,0,offset-240)
c2 = incRGB.Crop(0,offset,0,offset-239)
inc = ConditionalFilter(inc, inc.Crop(0,offset,0,0).AddBorders(0,0,0,offset), inc,
\            "RGBDifference(c1, c2) > thresh", args="c1, c2, thresh")
something you couldn't do at all easily without GRunT (ever tried converting a clip value to a string?)

Last edited by Gavino; 22nd August 2008 at 18:39. Reason: performance improvement
Gavino is offline   Reply With Quote
Old 23rd August 2008, 23:39   #9  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
You rock Gavino. I'm going to try your code with a few variations to try to improve accuracy.
4evrplan is offline   Reply With Quote
Old 24th August 2008, 00:10   #10  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
Okay, here's the whole thing modified to use GRunT. When I try to run this, I get the error message "ConditionalFilter does not have a named argument 'show'".

function BumpEven(clip inc, int offset, float thresh, clip incRGB)
{
c1 = incRGB.Crop(0,offset-1,0,offset-240)
c2 = incRGB.Crop(0,offset,0,offset-239)
inc = ConditionalFilter(inc, inc.Crop(0,offset,0,0).AddBorders(0,0,0,offset), inc,
\ "RGBDifference(c1, c2) > thresh", args="c1, c2, thresh")
return (offset > 1) ? BumpOdd(inc, offset-1, thresh, incRGB) : inc
}

function BumpOdd(clip inc, int offset, float thresh, clip incRGB)
{
c1 = incRGB.Crop(0,offset-1,0,offset-240)
c2 = incRGB.Crop(0,offset,0,offset-239)
inc = ConditionalFilter(inc,
\ inc.ConvertToRGB().Crop(0,offset,0,0).AddBorders(0,0,0,offset).ConvertToYV12(),
\ inc,
\ "RGBDifference(c1, c2) > thresh", args="c1, c2, thresh")
return (offset > 1) ? BumpEven(inc, offset-1, thresh, incRGB) : inc
}

function Bump(clip inc, int maxOffset, float thresh)
{
incRGB = inc.ConvertToRGB()
Assert(maxOffset > 0)
inc = (maxOffset % 2 == 0) ? BumpEven(inc, maxOffset, thresh, incRGB) :
\ BumpOdd(inc, maxOffset, thresh, incRGB)
return inc
}
4evrplan is offline   Reply With Quote
Old 24th August 2008, 10:26   #11  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by 4evrplan View Post
Okay, here's the whole thing modified to use GRunT. When I try to run this, I get the error message "ConditionalFilter does not have a named argument 'show'".
That's odd.

I've just tried out your exact script and it worked fine for me.
What version of Avisynth are you running (I'm on 2.58)?

EDIT: Tried again with Avisynth 2.57 and got the same error as you.

I will continue to investigate but a solution to your problem would be to upgrade now to the latest 2.58.

Last edited by Gavino; 24th August 2008 at 16:34.
Gavino is offline   Reply With Quote
Old 24th August 2008, 19:03   #12  |  Link
4evrplan
Registered User
 
Join Date: Feb 2008
Posts: 46
That did the trick. Easy Fix

EDIT: Now back to my core problem.
4evrplan is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 18:40.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.