Log in

View Full Version : Chroma stuttering, MergeChroma not working


j7n
30th July 2012, 10:58
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.

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.

cobo
30th July 2012, 11:53
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:

MPEG2Source("TestWish.d2v")
first=last
separatefields()
odd = SelectOdd()
even = SelectEven()
int = interleave(odd,even)
swap=weave(int)
MergeChroma(first,swap)

Or more simply:
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?

Gavino
30th July 2012, 13:46
MPEG2Source("TestWish.d2v")
first=last
separatefields()
odd = SelectOdd()
even = SelectEven()
int = interleave(odd,even)
swap=weave(int)
MergeChroma(first,swap)
Or more simply:
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.

j7n
30th July 2012, 15:31
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. :confused:

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 (http://www.fileden.com/files/2012/4/26/3297107/screens/testWish.demuxed.m2v) (2.5 MB)

jmac698
30th July 2012, 20:00
I see the problem. The color is a combination of two frames.

This script shows the problem clearly

#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:

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

jmac698
30th July 2012, 21:08
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:

#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)
}

j7n
31st July 2012, 00:59
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. :goodpost:

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.