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 > NLE - Non Linear Editing

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th June 2018, 16:25   #1  |  Link
TlatoSMD
Registered User
 
Join Date: Apr 2006
Posts: 65
Colorspaces: RGB, YUV, and gamma

Due to the difference in color space between RGB and YUV (aka the digital version of the latter with a much longer name), I've generally set my VLC player's gamma a bit lower in order to compensate, since most videos stored on DVDs, BDs, etc. are in YUV and my comp monitor is RGB. But now I have a problem: Russian studio Mosfilm have released a bunch of their Soviet-era films into the public domain in brilliant HD telecines around 2010 (back then, they put downloads on their official website) and recently uploaded them to their YouTube channel (replacing the c. 2010 website downloads thereby) and I've downloaded the Tarkovsky films...only to find that Mosfilm has uploaded them not as YUV but as RGB because they're meant for YT playback!

Now, you may say that I could just turn off the gamma correction in VLC, but I want real YUV files that I can also watch on a regular TV. First I tried the according RGB --> TV filter in Avidemux, but it only gave me incredibly blurry and washed out images with lots of artifacts, even if I was simply outputting to a visually lossless codec or converting the videos to one of my default household codecs and container beforehand. So next I tried Adobe PPro, where the issue could be easily fixed by setting a gamma filter from default 10 to 9, which then looks correct on my external RGB control monitor. Okay, exporting the gamma-fixed file from PPro...

But when I open the file with fixed gamma in VLC to play it back with my usual gamma setting for YUV videos, I notice that VLC's gamma filter also messes with color! Everything is shifted to green and yellowish, which is especially noticeable with the b/w films, but once I'd noticed, I also see it in the color footage. So I notice one downside to the VLC gamma filter is that you can only turn it on globally together with the hue filter, brightness filter, contrast filter, and saturation filter. I first suspected that the hue filter was set incorrectly, but fiddling with it only made matters worse, so I suppose that's not the issue.

It *SORTA* makes sense, remembering that unlike RGB, the bandwith or bitrate of each color channel is different in YUV, where green aka Y is the channel with the highest resolution or number of steps between clear white and clear black. None of this usually matters with all the proper YUV footage because the gamma ratio between all three channels is right, so the global gamma correction for all three channels in VLC for an RGB monitor will give me exactly what the raw footage looks like on a YUV monitor. But with RGB videos like this, all three channels have the same bitrate between clear black and clear white and thus relate differently to each other than they do in YUV, so it *SORTA* makes sense that gamma correction will result in an unwanted color shift here. But what's also weird is that I see no color shift at all in PPro when I'm correcting the RGB footage there, whether I'm shifting gamma up or down.

Anyway, so I figure I have to change the gamma in PPro for every single channel by means of the RGB color correction filter, in order to not only get proper gamma but also proper colors. Question: Do I do it on top of the global gamma filter from 10 to 9, or do I do it without that global gamma filter? If the default gamma on every channel on the RGB color correction filter is 1.00 and each slider has a minimum-maximum range from 0.10 to 9.99, how do I set each channel? The math in https://en.wikipedia.org/wiki/YUV and https://en.wikipedia.org/wiki/YCbCr looks too awfully complex for me.

Last edited by TlatoSMD; 20th June 2018 at 17:54.
TlatoSMD is offline   Reply With Quote
Old 20th June 2018, 17:32   #2  |  Link
TlatoSMD
Registered User
 
Join Date: Apr 2006
Posts: 65
And just saying, the original files were in HD and according to VLC, the RGB footage therein was encoded as ITU-R BT.709 (as such that the colors and gamma are still RGB, i. e. show correct on an RGB monitor but not on a YUV monitor), but I'm going for a DV/MPEG SD destination, so I need the right values not for RGB to ITU-R BT.709 but for RGB to ITU-R BT.601.

Last edited by TlatoSMD; 20th June 2018 at 18:01.
TlatoSMD is offline   Reply With Quote
Old 20th June 2018, 18:35   #3  |  Link
TlatoSMD
Registered User
 
Join Date: Apr 2006
Posts: 65
BTW, I've also tried the various things I could think of in VDub: Change input and output format, or use the 'convert format' filter. But none of them actually *DO* anything because they're all meant to keep things looking the same across different colorspaces, unlike what I do in PPro when I change the gamma from 10 to 9, which brightens the image up a little.
TlatoSMD is offline   Reply With Quote
Old 20th June 2018, 21:14   #4  |  Link
TlatoSMD
Registered User
 
Join Date: Apr 2006
Posts: 65
Okay, I *THINK* I've worked this out. After lots and lots and lots of googling, at last I found so-called "cofficients" for RGB to YCbCr which looked like single gamma values per channel. This is crucial, because most explanations of how to get from RGB to either YUV or YCbCr don't simply give these three gamma values but actually go through all this analogue electronic BS of difference values and color subsampling rather than give simple, specific gamma values.

So, what I found was this table on http://www.ilkeratalay.com/colorspacesfaq.php :

+----------------+---------------+-----------------+----------------+
| Recommendation | Coef. for red | Coef. for Green | Coef. for Blue |
+----------------+---------------+-----------------+----------------+
| Rec 601-1 | 0.2989 | 0.5866 | 0.1145 |
| Rec 709 | 0.2126 | 0.7152 | 0.0722 |
| ITU | 0.2220 | 0.7067 | 0.0713 |
+----------------+---------------+-----------------+----------------+

Understanding that in order to get away from the green and yellow tint that I get from the gamma correction in VLC, I knew I needed more red and blue, but not more green. Since the values for green are the largest for each format, I figured I'd go 1 minues (value). Trying the values for 601, the result was a dark purple image, which couldn't be right because the image has to be brighter, just like when I use global gamma and set it from 10 to 9. So figuring that Y aka green is the "standard" in YUV against which the other two colors are compared, I raised the green gamma from its computed position up to the default 1.00 and added the same number to the other two channel gammas. That looked better, so I rendered the result to HDD and looked at it in VLC plus gamma correction, and found the thing was still much too red, even though the global gamma fix in VLC did still make it a bit greener.

So next I tried the same thing with the values for 709 and ITU. Still too red. Paused to think. I remembered that in analogue YUV, the bandwith for U and V are identical, so I put in the same values for red and blue. The result looked a little better, but still not perfect. Hm. Since Y is least reduced in analogue YUV, why not just leave green alone, so that it will not move down with the other two channels before all three are bumped up again to make green the default 1.00 again?

BINGO! Only adding the 0.07 blue coefficient from ITU to both the blue and red channel gamma does the trick! Now the b/w looks like true b/w in VLC + gamma shift, and the color bits also look fine.
TlatoSMD is offline   Reply With Quote
Old 20th June 2018, 21:19   #5  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 466
You're so far out in left field it's hard to know where to begin, which likely explains why you're not getting any responses. Let's just say, those coefficients are not gamma values.

Last edited by videoh; 20th June 2018 at 21:21.
videoh is offline   Reply With Quote
Old 20th June 2018, 21:29   #6  |  Link
TlatoSMD
Registered User
 
Join Date: Apr 2006
Posts: 65
But I hope it's at least understandable how a video can be encoded in such a color space that it looks alright on an RGB monitor without any corrections, but too green and yellowish when outputting it to a YUV monitor or doing a standard YUV --> RGB gamma fix in VLC?

And just saying, I received a response only three minutes after the first time I've ever mentioned coeffcients. So I doubt that's actually the reason why nobody has replied to my first three posts for four hours.

Last edited by TlatoSMD; 20th June 2018 at 21:32.
TlatoSMD is offline   Reply With Quote
Old 20th June 2018, 21:58   #7  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 466
Quote:
Originally Posted by TlatoSMD View Post
a standard YUV --> RGB gamma fix in VLC
That's just a figment of your imagination. Please cite your source for this standard thing.
videoh is offline   Reply With Quote
Old 20th June 2018, 22:21   #8  |  Link
TlatoSMD
Registered User
 
Join Date: Apr 2006
Posts: 65
16-235 = 219 values.
0-255 = 266 values.

Any more questions?
TlatoSMD is offline   Reply With Quote
Old 20th June 2018, 22:29   #9  |  Link
videoh
Registered User
 
Join Date: Jul 2014
Posts: 466
Quote:
Originally Posted by TlatoSMD View Post
16-235 = 219 values.
0-255 = 266 values.

Any more questions?
Just wow.

BTW 0-255 is 256 values, not 266. And it is totally irrelevant anyway. It has nothing to do with gamma.

Well, good luck with your project.

Last edited by videoh; 20th June 2018 at 22:35.
videoh is offline   Reply With Quote
Old 25th June 2018, 03:33   #10  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,368
You need to do some homework

Video is generally encoded in YCbCr aka YUV, and is almost always done so using "limited range" 16-235 8 bit values (technically it's 16-240 for the chroma).

After decompressing the video, the player (really rendering engine inside the player of which there are many, see MadVR for an example) must convert the YUV back into RGB, since as you pointed out all monitors are actually RGB.

So, the player applies the appropriate matrix math to go from limited range YUV to full range RGB.
Blue_MiSfit is offline   Reply With Quote
Old 25th June 2018, 04:57   #11  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,777
Quote:
BTW 0-255 is 256 values, not 266.
Additional small point,
Quote:
16-235 = 219 values
Nope, actually 220 values. (16 and 235 inclusive, 0->1 is two values, including 0)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th June 2018 at 09:18.
StainlessS is offline   Reply With Quote
Old 6th July 2018, 16:01   #12  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 3,634
Quote:
Originally Posted by TlatoSMD View Post
But I hope it's at least understandable how a video can be encoded in such a color space that it looks alright on an RGB monitor without any corrections, but too green and yellowish when outputting it to a YUV monitor or doing a standard YUV --> RGB gamma fix in VLC?
The levels have to be expanded on playback.
The LCD PC monitor I bought a while ago doesn't default to full range luminance levels. It expected limited range levels unless you tell it otherwise. Maybe as PC monitors are often connected to something other than a PC these days, manufacturers have decided it's less hassle for the HDMI inputs to default to limited range?

For x264, the colorimetry is written to the video stream if you tell it to write it, and in theory a player should pay attention to that, otherwise it'll probably use Rec.601 for SD and Rec.709 for HD.

Here's a pixel shader for MPC-HC. It was originally designed to fix a graphic driver problem, but I fiddled with it so it'll work for any source. It converts Rec.709 to Rec.601, so if you have standard definition that's Rec.709 and the player's using Rec.601, it'll display correctly. The standard PC-TV level shaders are also in the zip file. https://files.videohelp.com/u/210984/Shaders.zip

Quote:
Originally Posted by TlatoSMD View Post
Understanding that in order to get away from the green and yellow tint that I get from the gamma correction in VLC, I knew I needed more red and blue, but not more green. Since the values for green are the largest for each format, I figured I'd go 1 minues (value). Trying the values for 601, the result was a dark purple image, which couldn't be right because the image has to be brighter, just like when I use global gamma and set it from 10 to 9. So figuring that Y aka green is the "standard" in YUV against which the other two colors are compared, I raised the green gamma from its computed position up to the default 1.00 and added the same number to the other two channel gammas. That looked better, so I rendered the result to HDD and looked at it in VLC plus gamma correction, and found the thing was still much too red, even though the global gamma fix in VLC did still make it a bit greener.
Don't forget, if you upscale or downscale and don't write the colour to the video stream the player will use different co-efficients according to the resolution.

As has been pointed out, TV vs PC levels and rec.709 vs Rec.601 are two different things. The difference between Rec.709 and Rec.601 isn't huge. The wrong levels will either make the picture look too dark or a bit "washed out".
I have an old version of VLC installed but it seems to be outputting full range levels. If you're using a HDMI input, does it expect full range levels?
If the video looks okay when played with a standard player connected to a standard TV, it'll be fine. They should expect limited levels and the TV will expand them to full range.

For the record, colourspace conversion can be done in Avisynth like this:
ColorMatrix(mode="Rec.709->Rec.601", clamp=0)
Levels conversion:
ColorYUV(Levels="TV->PC")
But seriously.... don't convert the levels unless you really know you need to. The problem probably isn't the video itself, but it's the encoding or playback stage where it's going wrong. Most likely playback. A monitor's HDMI inputs may default to full range or limited range, DVI will probably be full range and VGA is full range. Of course you should check there's no picture enhancing crap enabled in your video card's control panel. It may be doing horrible things.

Last edited by hello_hello; 6th July 2018 at 16:09.
hello_hello 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 02:20.


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