View Full Version : AVISynth - Overlay Colour Issue
Incast
3rd December 2007, 15:49
I'm getting very frustrated trying to get an AVISynth script to output in the colourspace I want.
Here's my code, where I overlay two interlaced sources for picture in picture:
a=MPEG2Source("I:\1.d2v").Crop(0,0,-2,0).AddBorders(0,0,2,0).Chromashift(C=-2).Trim(0,39844).AssumeTFF.SeparateFields
b=avisource("L:\2.avi").ConverttoYV12(interlaced=true).AssumeTFF.SeparateFields
BlankClip(length=39845, width=720, height=288, fps=50, color=$000000)
Overlay(a, x=0, y=0)
Overlay(b, x=508,y=15)
AssumeFieldbased
AssumeTFF
Weave
ConverttoYUY2(Interlaced=True)
KillAudio
a is YV12 rec601, b is YV12 rec601. I then overlay them on the blank clip before the conversion to YUY2, which should theoretically keep everything still in rec601.
However, after doing this the picture brightens. I've tried to correct it back from PC.601->Rec601 but it doesn't work, suggesting something else is going on.
If I use ConverttoYUY2 after blankclip but before overlay, it works fine. However, this solution is unacceptable as I need to perform the conversion to YUY2 once I have reinterlaced for the best quality.
Can anyone suggest any solutions to this?
Here's my present end product: http://i3.photobucket.com/albums/y76/incast/wrong.png
Here's how it should look: http://i3.photobucket.com/albums/y76/incast/correct.png
Wilbert
3rd December 2007, 18:41
However, after doing this the picture brightens.
That's odd, it shouldn't happen. Perhaps a bug?
The problem is that one of the input clips is RGB. Try
a = MPEG2Source("I:\1.d2v").Crop(0,0,-2,0).AddBorders(0,0,2,0).Chromashift(C=-2).Trim(0,39844).AssumeTFF.SeparateFields
b = avisource("L:\2.avi").ConverttoYV12(interlaced=true).AssumeTFF.SeparateFields
BlankClip(length=39845, width=720, height=288, fps=50, pixel_type="YV12", color_yuv=$108080)
Overlay(a, x=0, y=0)
Overlay(b, x=508,y=15)
AssumeFieldbased
AssumeTFF
Weave
ConverttoYUY2(Interlaced=True)
KillAudio
You might get better results with this:
a = MPEG2Source("I:\1.d2v").ConvertToYUY2(interlaced=true)
a = a.Crop(0,0,-2,0).AddBorders(0,0,2,0).Chromashift(C=-2).Trim(0,39844).AssumeTFF.SeparateFields
b = avisource("L:\2.avi").ConvertToYUY2(interlaced=true).AssumeTFF.SeparateFields
BlankClip(length=39845, width=720, height=288, fps=50, pixel_type="YUY2", color_yuv=$108080)
Overlay(a, x=0, y=0)
Overlay(b, x=508,y=15)
AssumeFieldbased
AssumeTFF
Weave
KillAudio
Incast
3rd December 2007, 18:56
Thank you Wilbert! The output is now perfect after moving the YUY2 conversion to the start.
I'm still not certain how my initial input was wrong, based on the documentation I was reading on the avisynth wiki. Probably my mistake I guess.
Anyway thanks once again!
Wilbert
3rd December 2007, 21:42
I'm still not certain how my initial input was wrong, based on the documentation I was reading on the avisynth wiki. Probably my mistake I guess.
No, i think it's a bug. But i need to do more tests to see where the problem is.
squid_80
4th December 2007, 10:16
I think it's because overlay by default will return a clip using the colorspace of the input clip. In your original script the input (blankclip) was using rgb24, so the first overlay call essentially returned "a" converted to rgb24.
I'm wondering why you need the blankclip line at all. Why not just do overlay(a, b, 508, 15) ?
Wilbert
4th December 2007, 19:16
I think it's because overlay by default will return a clip using the colorspace of the input clip. In your original script the input (blankclip) was using rgb24, so the first overlay call essentially returned "a" converted to rgb24.
Yes, i also think this happens, but it shouldn't change the lumarange.
IanB
4th December 2007, 21:37
@Incast,
How did you capture the 2 sample images?
If you display thisMPEG2Source("I:\1.d2v").ConvertToYUY2()are the levels correct or bright?
If you display thisMPEG2Source("I:\1.d2v").ConvertToYV12()are the levels correct or bright?
If you display thisMPEG2Source("I:\1.d2v").ConvertToRGB32()are the levels correct or bright?
Incast
5th December 2007, 01:13
The two sample images were video source pngs taken from virtualdubmod, with the avisynth output loaded in it. I also loaded in virtualdubmpeg2 to confirm the patterns, which it did.
The levels are correct in each case.
I don't know how much help these will be as the difference is almost impossible to see to the naked eye, but I guess you can proof the conversions mathematically should you wish:
http://i3.photobucket.com/albums/y76/incast/source-1.png Control: MPEG2Source("I:\1.d2v")
http://i3.photobucket.com/albums/y76/incast/YUY2.png YUY2: MPEG2Source("I:\1.d2v").ConvertToYUY2()
http://i3.photobucket.com/albums/y76/incast/YV12.png YV12: MPEG2Source("I:\1.d2v").ConvertToYUY2()
http://i3.photobucket.com/albums/y76/incast/RGB32.png RGB32: MPEG2Source("I:\99 France.d2v").ConvertToRGB32()
squid_80
5th December 2007, 08:04
Are you using the latest version of avisynth? (This reeks of that overlay pc_range bug that gave me nightmares.)
Incast
6th December 2007, 01:36
I'm using version 2.57.
IanB
26th December 2007, 13:23
Okay. Problem is bad RGB<->YUV conversion in Overlay. Now fixed in CVS.
Workaround:- Use external colour space conversions, i.e. ConvertToYUY2()/ConvertToRGB()
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.