Log in

View Full Version : How Is YUV410P10LE Encoded?


wswartzendruber
11th May 2020, 15:51
ADDENDUM: 420, not 410

I'm trying to figure out how YUV420P10LE is encoded. I surmise that first there are the luminance values, one for each pixel. Next, there are the Cb values, one for every four pixels. Then, there are the Cr values, also one for every four pixels.

Y, I assume, has 0 to represent the darkest amount of light and 1023 to represent the most amount of light. But how in the world are Cb and Cr mapped onto the color plane? I wasn't able to figure this out. Are they two's compliment?

I ultimately want to convert to and from RGB, given the appropriate colorspace constants.

shekh
12th May 2020, 19:25
Hope this will help:
yes it is plane by plane as you suggested.
1) get uint16 values
2) upscale Cb and Cr to picture dimensions (2x wide and 2x high)
3) conversion to RGB
Y is unsigned value with range 0 to 1023 (0 may be darkest or not - depends on full range flag)
subtract 512 from Cb/Cr to get signed value (useful signed range -512 to 511)
Refer to formulas here http://www.vapoursynth.com/doc/functions/resize.html (bottom of page "pixel range")

HowardWow1997
24th September 2020, 11:57
Hope this will help:
yes it is plane by plane as you suggested.
1) get uint16 values
2) upscale Cb and Cr to picture dimensions (2x wide and 2x high)
3) conversion to RGB
Y is unsigned value with range 0 to 1023 (0 may be darkest or not - depends on full range flag)
subtract 512 from Cb/Cr to get signed value (useful signed range -512 to 511)
Refer to formulas here http://www.vapoursynth.com/doc/functions/resize.html (bottom of page "pixel range")

Thank you for this

foxyshadis
24th September 2020, 14:35
If you're obtaining yuv420p10le then it's probably coming directly from ffmpeg, since other software tends to use the term P210. You should have ffmpeg upconvert it to yuv420p16le (or yuv444p16le) for you so that you don't have to do the messy work; it'll do it faster and better anyway.

wswartzendruber
18th December 2020, 02:00
If you're obtaining yuv420p10le then it's probably coming directly from ffmpeg, since other software tends to use the term P210. You should have ffmpeg upconvert it to yuv420p16le (or yuv444p16le) for you so that you don't have to do the messy work; it'll do it faster and better anyway.

I believe I will have FFMPEG output YUV444P16LE, as I don't care to get into the particulars of chroma subsampling.

Now, another question:

I have noticed that increasing the Y value does brighten a pixel, but also causes to appear desaturated. It looks like I have to modify the Cb and Cr components when I adjust Y. How does this work?

EDIT: Bonus question: Is it true that some YCbCr combinations are outside of the RGB colorspace? Are such values invalid?

StainlessS
18th December 2020, 21:03
but also causes to appear desaturated.
(In RGB) Full saturation has no white component. [EDIT: Except I guess for $000000 Black which could not be described as fully saturated]
If you had red $FF0000, it would be fully saturated, whereas $FF8080 would have a lot of impurity in it (white, governed by the lowest component).

[EDIT: Nah, above aint quite right, it involves max channel as well as min channel,
the closer the lowest channel gets to the highest channel , the less is the saturation.
Sat = Something like 1.0 - (min / max), or if max==0.0 then 0.0]

If you in YUV raise Y, so you are increasing white component and so less saturated.

It looks like I have to modify the Cb and Cr components when I adjust Y. How does this work?
Not sure that there is an answer for that, only really works properley in RGB,
but ColorYUV(cont_u=8,cont_v=8) would raise U & V contrast [approx saturation increase] from center $80 [moving out from center] whereas
ColorYUV(cont_u= -8,cont_v= -8) would reduce saturation. U & V contrast would normally be kept same else color shift.
The numbers dont quite work right changing Y, you cant really say how U & V should be changed, but maybe both in same [contrast] direction as Y change
although by how much [and may not be possible] to get exactly right [and probably not same change for both U & V].
Also, would change all the colors in image differently, the numbers just dont work well for YUV.

combinations are outside of the RGB colorspace
Think YUV = $00FFFF (PC Levels for all 3 channels, chroma center=$80), would be fully saturated BLACK or $000000 also fully saturated black.
Also, YUV = $FFFFFF or $FF0000 would be fully saturation white, just cant happen, they are mythical colors outside of RGB colorspace.
[Or also $00FF00 or $0000FF, or $FFFF00, or $FF00FF, all totally impossible, as are many others]

Others may [and probably will] give a better reply to your perfectly good questions [I did my best, it was crap :) ].