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 July 2012, 10:58   #1  |  Link
j7n
Registered User
 
j7n's Avatar
 
Join Date: Apr 2006
Posts: 80
Chroma stuttering, MergeChroma not working

I am trying to correct a clip with chroma jumping ahead and lagging behind on odd and even fields of an interlaced video. I tried using MergeChroma() and this function appears to do nothing.

The clip is in YV12 format. I also tried writing int out to an uncompressed file, and the result was the same.

Code:
MPEG2Source("TestWish.d2v")
separatefields()
odd = SelectOdd()
even = SelectEven()
int = Interleave(odd,even)
MergeChroma(last,int)
Clips "last" and "int" are different, yet the output of MergeChroma is visually indistinguishable from last. Tried AviSynth 2.5.6, 2.5.8 and 2.6.0. I am probably missing something very stupid.
j7n is offline   Reply With Quote
Old 30th July 2012, 11:53   #2  |  Link
cobo
Registered User
 
Join Date: Mar 2004
Posts: 118
Isn't "last" in your script the separated fields clip? The clip it produces would be half height. Also you need to use "weave" after "interleave".Try this instead:

Quote:
MPEG2Source("TestWish.d2v")
first=last
separatefields()
odd = SelectOdd()
even = SelectEven()
int = interleave(odd,even)
swap=weave(int)
MergeChroma(first,swap)
Or more simply:
Quote:
MPEG2Source("TestWish.d2v")
swap=SwapFields()
MergeChroma(last,swap)
Those may not work the way you want them to depending on the field-dominance of your original clip. What does "info()" display for parity of your original clip?

Last edited by cobo; 30th July 2012 at 13:42.
cobo is offline   Reply With Quote
Old 30th July 2012, 13:46   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by cobo View Post
Code:
MPEG2Source("TestWish.d2v")
first=last
separatefields()
odd = SelectOdd()
even = SelectEven()
int = interleave(odd,even)
swap=weave(int)
MergeChroma(first,swap)
Or more simply:
Code:
MPEG2Source("TestWish.d2v")
swap=SwapFields()
MergeChroma(last,swap)
Those two scripts are not equivalent.
In the first one, 'swap' has the same contents as 'first', since Interleave preserves the parity of each field.
The second script is probably what j7n needs.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 30th July 2012, 15:31   #4  |  Link
j7n
Registered User
 
j7n's Avatar
 
Join Date: Apr 2006
Posts: 80
Thank you for your replies.

Yes, "last" was the field-separated clip, which I previewed to monitor what was going on. I would have woven the fields together later once they had correct color. The parity is BFF.

swap=SwapFields()
MergeChroma(last,swap)


... also produced an identical clip to the source. MergeChroma does do something if I feed a completely different clip to it, but not here.

I looked at the video again, and perhaps swapping color fields is not enough to fix it. It is a film that has been slowed down by displaying each field three times, and color was messed up in the process.

The clip (2.5 MB)
j7n is offline   Reply With Quote
Old 30th July 2012, 20:00   #5  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
I see the problem. The color is a combination of two frames.

This script shows the problem clearly
Code:
#possible chroma lag
dir="C:\Documents and Settings\me\My Documents\Downloads\videoprojects\"
fn="testWish.demuxed.d2v"
MPEG2Source(dir+fn, cpu=0)
Crop(0, 52, -0, -52)
SeparateFields()
u=utoy
y=last.bilinearresize(360,144).greyscale
stackvertical(y,u)
Nothing as simple as swapping fields will fix it. You need to do a chroma replacement on select frames. Here's the pattern:
Code:
field  contents
84 film t0, use chroma -2
85 film t1, use chroma +2
86 ok film b1
87 ok film t1
88 ok film t2
89 ok film b2

Last edited by jmac698; 30th July 2012 at 20:37.
jmac698 is offline   Reply With Quote
Old 30th July 2012, 21:08   #6  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,860
This seems to be 16fps standard 8mm film, with 2:3 pulldown in PAL, to show at 16.67fps.
http://en.wikipedia.org/wiki/Telecine

Ok, this works but only for frame 27 on. There is a pattern but it seems to break. You'll have to take it from here. The actual framerate here is 2/3, and the bad frame is one you can throw out, so if you throw out all combed frames you'll get the original progessive frames and you can slow them down again in the pattern of your choice.
chroma_replace(false) fixes the bad frames
chroma_replace(true) returns only the progressive frames, but only for a while.
Checkout fields 84 and 85, you can see they are definitely fixed. You can see the difference, for example by changing newf0, newf1 to f0, f1.

And, the script to fix it:
Code:
#possible chroma lag
dir="C:\Documents and Settings\me\My Documents\Downloads\videoprojects\"
fn="testWish.demuxed.d2v"
MPEG2Source(dir+fn, cpu=0)
Crop(0, 52, -0, -52)
LabelVideoWithCounts
#Fix the chroma in 1 frame of 3 by replacing the chroma in two of it's fields
chroma_replace(false)

function chroma_replace(clip v, bool progressive) {
    #Function to replace chroma in select fields
    cycle=6
    v.assumeframebased.separatefields
    f0=selectevery(cycle,0)
    f1=selectevery(cycle,1)
    f2=selectevery(cycle,2)
    f3=selectevery(cycle,3)
    f4=selectevery(cycle,4)
    f5=selectevery(cycle,5)
    chroma=selectevery(cycle, -2)
    newf0=mergechroma(f0, chroma)
    chroma=selectevery(cycle, 2)
    newf1=mergechroma(f1, chroma)
    progressive?interleave(f3,f2,f4,f5):interleave(newf0, newf1, f2, f3, f4, f5)
    weave
}

function show(clip v) {
    #Show the luma next to the chroma to illustrate chroma problems
    SeparateFields()
    u=utoy
    y=last.bilinearresize(u.width, u.height).greyscale
    stackvertical(y,u)
}

function LabelVideoWithCounts(clip v) {
    #Add framecount and field counts to a video
    v
    #add frame numbering
    separatefields
    top=last.selecteven
    bot=last.selectodd
    #all this is to remove color shadows; where the text overlays, color is desaturated, due to YV12
    tu=top.utoy
    tv=top.vtoy
    bu=bot.utoy
    bv=bot.vtoy
    top1=top.ScriptClip("""subtitle("video field = " + string(current_frame*2),x=-1,y=60,size=20,text_color=$00FFFFFF,font_width=17)""")
    bot1=bot.ScriptClip("""subtitle("video field = " + string(current_frame*2+1),x=-1,y=80,size=20,text_color=$00FFFFFF,font_width=17)""")
    top=ytouv(tu,tv,top1)
    bot=ytouv(bu,bv,bot1)
    interleave(top,bot)
    weave
    assumefps(v.framerate)
}

Last edited by jmac698; 30th July 2012 at 22:58.
jmac698 is offline   Reply With Quote
Old 31st July 2012, 00:59   #7  |  Link
j7n
Registered User
 
j7n's Avatar
 
Join Date: Apr 2006
Posts: 80
Took me a while to understand the script. The grayscale clip demonstrates the problem well, better than I could see in color, and also allows to sync up to the Cycle. Thank you.

I didn't realize there was such a thing as 16fps film and assumed it was slowed down for artistic purposes, since it's mixed with 25fps material. Anyway, I'll make a VFR clip out of it. Also, I'm gonna start use functions from now on, which I never did before.

Last edited by j7n; 31st July 2012 at 01:10.
j7n 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 08:16.


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