Log in

View Full Version : The amazing lossy Color Space Convertion RGB 2 YUV thread !


aleste81
27th November 2007, 01:24
So you are used to capture to YUY2, then edit in RGB with VirtualDub,
then back to YUY2 for some AviSynth filtering, then YV12 for compression, huh ?

Then see for yourself what happens each time you convert from RGB to YUV :

http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB_to_YUY2_to_RGB_(000_time).gif


Original RGB

http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB_to_YUY2_to_RGB_(000_time).png


RBG to YUY2 to RBG 35 times

http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB_to_YUY2_to_RGB_(035_times).png


RBG to YUY2 to RBG 70 times

http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB_to_YUY2_to_RGB_(070_times).png


RBG to YUY2 to RBG 215 times

http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB_to_YUY2_to_RGB_(215_times).png


RBG to YUY2 to RBG 700 times

http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB_to_YUY2_to_RGB_(700_times).png


Note : the video used is from VirtualDub 1.7.6 menu Tools | Create Test Video | RGB Cube, frameserved.
The AviSynth script used is

AVISource("RBGCube.vdr")
ConvertToYUY2()
ConvertToRGB()
ConvertToYUY2()
ConvertToRGB()
...

repeated many times.

Edit (from squid_80 suggestion) :
The is no color shift is you use ConvertBackToYUY2() instead of ConvertToYUY2()

From http://avisynth.org/mediawiki/ConvertToYUY2
«Conversion back and forth is not lossless, so use as few conversions as possible. If multiple conversions are necessary, use ConvertBackToYUY2() to convert back to YUY2, when you applied a YUY2->RGB conversion prior to that in your script. This will reduce colorblurring, but there are still some precision lost.»

sillKotscha
27th November 2007, 01:51
So you are used to capture to YUY2, then edit in RGB with VirtualDub,
then back to YUY2 for some AviSynth filtering, then YV12 for compression, huh ?

no, I've captured lossless, edit lossless, convert to YV12 / add filters -> encode ;)

squid_80
27th November 2007, 02:29
This is why there's an avisynth function called convertbacktoyuy2.

(Nobody in their right mind would do 35 conversions, let alone 700!)

MfA
27th November 2007, 03:54
Still, the bias of the drift to the left is curious ...

squid_80
27th November 2007, 03:59
Not really. One conversion is assuming yuy2 chroma samples are the horizontal average of 2 pixels, the other conversion is assuming yuy2 chroma is only from the left pixel in each left-right pair.

MfA
27th November 2007, 04:31
Hmm, I see it's a known bug. It's still strange though, it's very wrong and serves no purpose. Even if the 1/2-1/2 weighting is faster than a larger filter that doesn't matter, it's not properly centered ... point sampling is and is faster still, it's just plain better. Dunno what Ben Rudiak-Gould was thinking there.

FlimsyFeet
27th November 2007, 10:03
no, I've captured lossless, edit lossless, convert to YV12 / add filters -> encode ;)I capture with lossless compression, but I still capture YUY2. I was told that Bt878 cards use YUY2 nativley, and if you request RGB output then it's just upsampled internally. I only do any colorspace conversions if necessary to use for a particular avisynth filter.

aleste81
27th November 2007, 17:17
no, I've captured lossless, edit lossless, convert to YV12 / add filters -> encode ;)

I suppose you mean RBG when you say lossless ?
The problem is that SpatialSoften requires YUY2. So at least you have some RGB --> YUY2 --> YV12.

Plus I don't really know what does VirtualDub do in its internals, menu Video |Color Depth.

aleste81
30th November 2007, 01:01
Hi, you guys, I have investigated the problem more and now I am pissed x1000.

Look at these pictures, they show the difference between VirtualDub, AviSynth, HuffYUV, Ffdshow about RGB-YUY2-YV12 convertions. None of them is the same !

http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x1.png
http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x2a.png
http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x2b.png
http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x2c.png
http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x2d.png
http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x3a.png
http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x3b.png
http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/RGB-YUV-x3c.png

Even worse, ffdshow extension of HuffYUV on YV12, displays a different image when opened in VirtualDub and opened in a AviSynth script !

Get the rar here for more pictures
http://membres.lycos.fr/ttest/pub/IMAGES/F...M9/RGB_2_YUV/1/ (http://membres.lycos.fr/ttest/pub/IMAGES/FORUMS/DOOM9/RGB_2_YUV/1/)

2Bdecided
5th December 2007, 16:27
YV12 can be interlaced or progressive. The colour encoding is different depending on which is chosen. Did all conversions use the same setting in this respect?

In the pictures you've posted, how did you convert back to RGB for display?

Cheers,
David.

aleste81
3rd October 2008, 00:57
In the pictures you've posted, how did you convert back to RGB for display?

There is no loss when you convert YV12 to RGB. There are screen capture from VirtualDub.

I submitted the YV12 problem on virtualdub forum and they acknowledged the bug in VD YV12 handling.
It is fixed now.

Guest
3rd October 2008, 01:00
Link to VirtualDub forum thread, please?

Revgen
3rd October 2008, 08:34
Link to VirtualDub forum thread, please?

http://forums.virtualdub.org/index.php?act=ST&f=5&t=14892&hl=&

2Bdecided
4th October 2008, 23:39
There is no loss when you convert YV12 to RGB.That's a bold statement, and demonstrably wrong, but my post wasn't concerned with that: I was simply pointing out that the choice of interlaced or progressive is vital for YV12, and that's one of the things that can go wrong / account for differences.

This is discussed in your other thread, but I hadn't seen that at the time.

Cheers,
David.