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 30th January 2014, 23:56   #1  |  Link
Kyaneos
Registered User
 
Join Date: Nov 2005
Posts: 24
Deinterlace Problems

Hi guys:

I'm capturing a cartoon movie interlaced from an old VHS tape with Lagarith codec, interlacing is "Field blended norm-conversion", I used many filters (TDeint, TMC, AnimeIVTC, TempGaussMC_Beta1, QTGMC etc.) but I can not delete the following artifacts:















Here uncompressed two samples:

https://mega.co.nz/#!SdIiXK6b!fjPWF_...s3Gf2-TaURHMZw

https://mega.co.nz/#!3MYHyCRb!W-Yf4Q...P9vcgLcJh2mUkc

Is there a deinterlace filter, settings, or postprocessing filter to fix it?

Thanks a lot.
Kyaneos is offline   Reply With Quote
Old 31st January 2014, 00:24   #2  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 625
Ohhh, TVE2... old memories. Maybe you can try http://forum.doom9.org/showthread.php?t=166834

This artefact is chroma blend, if I am not wrong. Saludos.

EDIT: Change for avoiding confusion.
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Nvidia GTX750 2GB DDR5 + SSD Vertex 4 256 GB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite

Last edited by Overdrive80; 31st January 2014 at 12:15.
Overdrive80 is offline   Reply With Quote
Old 31st January 2014, 02:09   #3  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
it's chroma blend
feisty2 is offline   Reply With Quote
Old 31st January 2014, 02:55   #4  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 981
Are you using ConverttoYV12() somewhere in your script?
Stereodude is offline   Reply With Quote
Old 31st January 2014, 12:12   #5  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 625
Quote:
Originally Posted by feisty2 View Post
it's chroma blend
Thanks for clarification. ^^
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Nvidia GTX750 2GB DDR5 + SSD Vertex 4 256 GB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite
Overdrive80 is offline   Reply With Quote
Old 31st January 2014, 12:32   #6  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
luma = tfm(pp=0, slow=2)
chroma = vinverse().Srestore(omode="PP3", cache=10)

# manual sync: figure out which frame (previous,current aka p,c) of 'chroma' clip is most similar to current frame of 'luma' clip

# 46*log(|x-y|+1) uses the full [0,255]-range and scales little differences better than |x-y|*2
diffp = mt_lutxy(luma,chroma.selectevery(1,-1),"x y - abs 1 + log 46 *")
diffc = mt_lutxy(luma,chroma, "x y - abs 1 + log 46 *")

# average difference between compared frames
mp = mt_lutf(diffp,diffp,"avg",expr="x")
mc = mt_lutf(diffc,diffc,"avg",expr="x")

# build conditional masks based on the caculated comparisons
maskp = mt_lutxy(mp,mc,"x y < 255 0 ?")

# finally merge the luma of the tfm with the chroma of the srestore clip accordingly to the binary mask
MergeChroma(luma,chroma).mt_merge(chroma.selectevery(1,-1),maskp,luma=true,Y=2,U=3,V=3)

try this script, should fix the problem
feisty2 is offline   Reply With Quote
Old 31st January 2014, 16:59   #7  |  Link
Kyaneos
Registered User
 
Join Date: Nov 2005
Posts: 24
Quote:
Originally Posted by Overdrive80 View Post
Ohhh, TVE2... old memories. Maybe you can try http://forum.doom9.org/showthread.php?t=166834

This artefact is chroma blend, if I am not wrong. Saludos.

EDIT: Change for avoiding confusion.
AutoChromaFix don't work for me

Quote:
Originally Posted by Stereodude View Post
Are you using ConverttoYV12() somewhere in your script?
Yes, this is the first point of my script, I capture with Lagarith in yuy2 and I use the command "ConverttoYV12".

Quote:
Originally Posted by feisty2 View Post
luma = tfm(pp=0, slow=2)
chroma = vinverse().Srestore(omode="PP3", cache=10)

# manual sync: figure out which frame (previous,current aka p,c) of 'chroma' clip is most similar to current frame of 'luma' clip

# 46*log(|x-y|+1) uses the full [0,255]-range and scales little differences better than |x-y|*2
diffp = mt_lutxy(luma,chroma.selectevery(1,-1),"x y - abs 1 + log 46 *")
diffc = mt_lutxy(luma,chroma, "x y - abs 1 + log 46 *")

# average difference between compared frames
mp = mt_lutf(diffp,diffp,"avg",expr="x")
mc = mt_lutf(diffc,diffc,"avg",expr="x")

# build conditional masks based on the caculated comparisons
maskp = mt_lutxy(mp,mc,"x y < 255 0 ?")

# finally merge the luma of the tfm with the chroma of the srestore clip accordingly to the binary mask
MergeChroma(luma,chroma).mt_merge(chroma.selectevery(1,-1),maskp,luma=true,Y=2,U=3,V=3)

try this script, should fix the problem
The script doesn't work, the result is the same I use it without using it:





This is the script:
Code:
AVISource ("C:\Home.avi")

ConverttoYV12()
AssumeTFF()
AnimeIVTC(mode=2)
luma = tfm(pp=0, slow=2)
chroma = vinverse().Srestore(omode="PP3", cache=10)

# manual sync: figure out which frame (previous,current aka p,c) of 'chroma' clip is most similar to current frame of 'luma' clip

# 46*log(|x-y|+1) uses the full [0,255]-range and scales little differences better than |x-y|*2
diffp = mt_lutxy(luma,chroma.selectevery(1,-1),"x y - abs 1 + log 46 *")
diffc = mt_lutxy(luma,chroma, "x y - abs 1 + log 46 *")

# average difference between compared frames
mp = mt_lutf(diffp,diffp,"avg",expr="x")
mc = mt_lutf(diffc,diffc,"avg",expr="x")

# build conditional masks based on the caculated comparisons
maskp = mt_lutxy(mp,mc,"x y < 255 0 ?")

# finally merge the luma of the tfm with the chroma of the srestore clip accordingly to the binary mask
MergeChroma(luma,chroma).mt_merge(chroma.selectevery(1,-1),maskp,luma=true,Y=2,U=3,V=3)
Crop(24,10,-24,-20)
Lanczos4Resize(720,576)
I'm starting to lose hope

Last edited by Kyaneos; 31st January 2014 at 17:07.
Kyaneos is offline   Reply With Quote
Old 31st January 2014, 19:04   #8  |  Link
davidhorman
I'm the Doctor
 
Join Date: Jan 2004
Posts: 1,512
I've just had a quick look - is it me, or is the chroma interlaced out of sync with the luma?

Code:
a=avisource("sample1.avi").assumetff
b=a.separatefields.doubleweave.selectodd
mergechroma(b,a)
seems to give a clearer view of the problem, at least.
davidhorman is offline   Reply With Quote
Old 31st January 2014, 19:19   #9  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,057
The following code shifts the chroma and fixes the problem, but it also introduces the problem on the other side of each object. Here's a before/after:



What's needed is a way to combine this code with a mask so that it only applies to chroma differences below and to the right of chroma transitions.
Code:
LoadPlugin("c:\Program Files\AviSynth 2.5\plugins\CNR\Cnr2.dll")

source=AVISource("E:\Documents\Dnload\UNPACK\Sample1.avi").killaudio().AssumeBFF()
chroma=source.Cnr2("oxx",8,16,191,100,255,32,255,false) 
output=ChromaFix(chroma)

stackhorizontal(source,output)
#return output

#-------------------------------

function ChromaFix(clip source)
{
  Vshift=2 # 2 lines per bobbed-field per tape generation (PAL); original=2; copy=4 etc
  Hshift=2 # determine experimentally 
  fields=source.SeparateFields() # separate by fields
  fields=MergeChroma(fields,crop(fields,Hshift,Vshift,0,0).addborders(0,0,Hshift,Vshift))
  Weave(fields)
}
johnmeyer is offline   Reply With Quote
Old 31st January 2014, 19:22   #10  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 981
Quote:
Originally Posted by Kyaneos View Post
Yes, this is the first point of my script, I capture with Lagarith in yuy2 and I use the command "ConverttoYV12"
You're not using the command correctly. You need to set interlaced=true in the call.

like this:
ConvertToYV12(interlaced=true)

Last edited by Stereodude; 31st January 2014 at 21:29. Reason: give example
Stereodude is offline   Reply With Quote
Old 1st February 2014, 05:06   #11  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
xxxsource ()
tfm ().tdecimate ()
converttoyv12 ()
feisty2 is offline   Reply With Quote
Old 1st February 2014, 18:31   #12  |  Link
Kyaneos
Registered User
 
Join Date: Nov 2005
Posts: 24
Quote:
Originally Posted by Stereodude View Post
You're not using the command correctly. You need to set interlaced=true in the call.

like this:
ConvertToYV12(interlaced=true)
This doesn't solve the problem.

Quote:
Originally Posted by feisty2 View Post
xxxsource ()
tfm ().tdecimate ()
converttoyv12 ()
The problem persists
Kyaneos is offline   Reply With Quote
Old 1st February 2014, 19:55   #13  |  Link
Stereodude
Registered User
 
Join Date: Dec 2002
Location: Region 0
Posts: 981
Quote:
Originally Posted by Kyaneos View Post
This doesn't solve the problem.
Well, the problem is in the capture. It's not being caused by incorrect settings in AVIsynth as I initially guessed.

I'm not sure your captures can be fixed. It seems to have been damaged beyond what can be repaired. The Chroma from the two interlaced fields is merged. As such it will never line up with the luma correctly.

Open this script in VirtualDub to see what I mean:

Code:
AVISource("sample1.avi", pixel_type="YUY2").assumetff()
clip1=separatefields().selecteven()
clip2=separatefields().selectodd()
clip1u=(clip1.UToY())
clip1v=(clip1.VToY())
clip2u=(clip2.UToY())
clip2v=(clip2.VToY())
clip1chroma=YToUV(clip1u,clip1v)
clip2chroma=YToUV(clip2u,clip2v)
clip1luma=clip1.Greyscale()
clip2luma=clip2.Greyscale()
chromastack=stackvertical(clip1chroma,clip2chroma)
lumastack=stackvertical(clip1luma,clip2luma)
stackvertical(chromastack,lumastack)
Step through a few frames and the problem should be quite apparent. The even fields are on top and the odd ones are on the bottom. You'll see the Chroma is identical for them, but the luma is not.

Last edited by Stereodude; 1st February 2014 at 20:00.
Stereodude is offline   Reply With Quote
Old 1st February 2014, 21:19   #14  |  Link
davidhorman
I'm the Doctor
 
Join Date: Jan 2004
Posts: 1,512
Kyaneos, are these samples completely un-reencoded cuts of captures? You didn't run them through VirtualDub (except by Direct Stream Copy) or anything to cut them?

Quote:
I'm not sure your captures can be fixed. It seems to have been damaged beyond what can be repaired.
I disagree; the situation can certainly be improved, to a degree.

First problem: either the broadcast or the capture was weird, and the fields are out of sync, so there's an AA AB BB BC CC pattern going on (most of the animation is "shot on twos", but some of the backgrounds and camera moves are 25fps).

Code:
separatefields.doubleweave.selectodd
fixes that, but somehow re-interlaces the chroma! So:

Code:
a=avisource("sample1.avi").assumetff
b=a.separatefields.doubleweave.selectodd
mergechroma(b,a)
The above gives us the problem in its simplest form - progressive 25fps frames with blended chroma. Because the animation is (mostly) shot on twos, one can simply replace the chroma on the "bad" frames with chroma from a good neighbour.

Code:
a=avisource("sample2.avi").assumetff
b=a.separatefields.doubleweave.selectodd
mergechroma(b,a.selectevery(2,0,2))
This fixes it right up until the last frame (which could be a capture artefact).

The first sample seems to have a dropped frame, so the pattern needs to change slightly halfway through, and around there one frame will always be stuck with blended chroma:

Code:
a=avisource("sample1.avi").assumetff
b=a.separatefields.doubleweave.selectodd
pattern1=mergechroma(b,a.selectevery(2,0,2))
pattern2=mergechroma(b,a.selectevery(2,1,1))
return pattern1.trim(0,454)+pattern2.trim(455,0)
This is a reasonable stab at correcting it.

However, some of the animation in the first clip (backgrounds, zooms, and some foreground animation, frames 243 to 266) is "shot on ones" - one cel per frame - instead of "shot on twos" - one cel per two frames - as the second sample is in its entirety. This means there is still some residual chroma blending on certain parts (the beach near the end being the most obvious example).

This remaining chroma does seem to be fully blended, and while you could theoretically work backwards and forwards from good "shot on twos" frames, subtracting as you go through the "shot on ones" sequences, in reality you'd rapidly build up too much noise for this to be even worth attempting. If you're a glutton for punishment, though, that blended frame caused by the dropped frame in sample1 can be fixed that way.

So, there you go. I think the majority of the blending can be removed simply by dropping the bad frames of chroma and replacing them with good ones. Due to dropped frames you may need to change that selectevery every now again - it'll probably need to switch between (2,0,2) and (2,1,1) as above, or possibly also (2,0,0) and (2,-1,1).

And now, back to what I was supposed to be working on today until this distracted me!

David

Last edited by davidhorman; 1st February 2014 at 21:22.
davidhorman is offline   Reply With Quote
Old 2nd February 2014, 01:33   #15  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,057
David,

That's really good stuff!
johnmeyer is offline   Reply With Quote
Old 4th February 2014, 19:31   #16  |  Link
Kyaneos
Registered User
 
Join Date: Nov 2005
Posts: 24
Quote:
Originally Posted by davidhorman View Post
Kyaneos, are these samples completely un-reencoded cuts of captures? You didn't run them through VirtualDub (except by Direct Stream Copy) or anything to cut them?



I disagree; the situation can certainly be improved, to a degree.

First problem: either the broadcast or the capture was weird, and the fields are out of sync, so there's an AA AB BB BC CC pattern going on (most of the animation is "shot on twos", but some of the backgrounds and camera moves are 25fps).

Code:
separatefields.doubleweave.selectodd
fixes that, but somehow re-interlaces the chroma! So:

Code:
a=avisource("sample1.avi").assumetff
b=a.separatefields.doubleweave.selectodd
mergechroma(b,a)
The above gives us the problem in its simplest form - progressive 25fps frames with blended chroma. Because the animation is (mostly) shot on twos, one can simply replace the chroma on the "bad" frames with chroma from a good neighbour.

Code:
a=avisource("sample2.avi").assumetff
b=a.separatefields.doubleweave.selectodd
mergechroma(b,a.selectevery(2,0,2))
This fixes it right up until the last frame (which could be a capture artefact).

The first sample seems to have a dropped frame, so the pattern needs to change slightly halfway through, and around there one frame will always be stuck with blended chroma:

Code:
a=avisource("sample1.avi").assumetff
b=a.separatefields.doubleweave.selectodd
pattern1=mergechroma(b,a.selectevery(2,0,2))
pattern2=mergechroma(b,a.selectevery(2,1,1))
return pattern1.trim(0,454)+pattern2.trim(455,0)
This is a reasonable stab at correcting it.

However, some of the animation in the first clip (backgrounds, zooms, and some foreground animation, frames 243 to 266) is "shot on ones" - one cel per frame - instead of "shot on twos" - one cel per two frames - as the second sample is in its entirety. This means there is still some residual chroma blending on certain parts (the beach near the end being the most obvious example).

This remaining chroma does seem to be fully blended, and while you could theoretically work backwards and forwards from good "shot on twos" frames, subtracting as you go through the "shot on ones" sequences, in reality you'd rapidly build up too much noise for this to be even worth attempting. If you're a glutton for punishment, though, that blended frame caused by the dropped frame in sample1 can be fixed that way.

So, there you go. I think the majority of the blending can be removed simply by dropping the bad frames of chroma and replacing them with good ones. Due to dropped frames you may need to change that selectevery every now again - it'll probably need to switch between (2,0,2) and (2,1,1) as above, or possibly also (2,0,0) and (2,-1,1).

And now, back to what I was supposed to be working on today until this distracted me!

David
David, first, many thanks for the explanation, fantastic job!

These samples completely un-reencoded, they just have been cut with Vitual Dub (Direct Stream Copy).

A doubt, using these scripts, would it be necessary to deinterlace?

Thanks for everything
Kyaneos is offline   Reply With Quote
Old 4th February 2014, 21:30   #17  |  Link
davidhorman
I'm the Doctor
 
Join Date: Jan 2004
Posts: 1,512
It shouldn't be necessary to deinterlace - the script unweaves the fields and puts them back in the right order, and leaves you with progressive frames.

That said, there may be a filter you could run to more neatly line up the fields - there's a horizontal flicker between odd and even (most noticeable if you bob and look at the left hand blanking edge).
__________________
My AviSynth filters / I'm the Doctor
davidhorman is offline   Reply With Quote
Old 5th February 2014, 00:20   #18  |  Link
Kyaneos
Registered User
 
Join Date: Nov 2005
Posts: 24
Quote:
Originally Posted by davidhorman View Post
It shouldn't be necessary to deinterlace - the script unweaves the fields and puts them back in the right order, and leaves you with progressive frames.

That said, there may be a filter you could run to more neatly line up the fields - there's a horizontal flicker between odd and even (most noticeable if you bob and look at the left hand blanking edge).
True, I have seen the horizontal flicker, you know any filter to fix the problem?
Kyaneos 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 12:42.


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