Best output colour space, and how to achieve it...?
#1
I'd like to know what's the best output colour space for Kodi on the Raspberry Pi.

There have been some threads about this before - notably https://forum.kodi.tv/showthread.php?tid=252023 -  but a) they tend not to come to any firm conclusions, with a lot of conflicting statements, b) they're old enough that any authoritative-sounding posts pre-date Kodi v17 (and in many cases even pre-date Kodi v16), and c) they mostly focus on Kodi running on Intel hardware, which doesn't necessarily work the same way as Kodi running on an RPi, and (I think) gives you additional configuration options within Kodi itself that I don't seem to have! So I hope no one minds if I start a new thread about it. Smile

I'm running LibreELEC (currently at v8.2.0.1) on a Raspberry Pi 3. (If I could get better results by running Kodi a different way, I'd be happy to switch!). The output from the RPi 3 goes to a Lumagen RadiancePro video processor, and from there to an LG G6 television. The RadiancePro does all kinds of interesting and helpful things, such as particularly-good-quality upscaling, 3D LUT colour correction, and so on. But to work at its best, the signal you feed it needs to be in the most "raw" form possible - in other words, as close as possible to the original video-file data.

The majority of video material is encoded as YCbCr, 4:2:0, and uses 16 for black and 235 for white (as opposed to the RGB, 4:4:4, 0-255 space that is used by most computers). So, ideally, I would want the RPi3 to output the original YCbCr 4:2:0 video data, and let the RadiancePro deal with everything from that point on. (If this results in the Kodi UI getting a little messed up, I'm absolutely fine with that, so long as the video itself is pristine).

The question is, how close can one get to passing through the raw video data? My RPi 3 with LibreELEC defaults to RGB output rather than YCbCr, and I think also defaults to 0-255. I've discovered that it's possible to make it output YCbCr 16-235 by changing the config.txt file in the boot directory, and setting the hdmi_pixel_encoding value - I'm currently experimenting with setting it to 3. But there are two possible issues with that.

The first is that it's now outputting YCbCr 4:4:4. YCbCr 4:2:2 would be better, and 4:2:0 would be better still, but I haven't yet found a way to make it do that. Is that possible?

The more serious issue, though, is the question of whether, if we do output YCbCr, is Kodi/LibreELEC really giving us the original video information (plus minimal chroma upsampling if we're at 4:2:2 or 4:4:4), or are there actually other colour space transformations going on internally? In the aforementioned earlier threads, there is some talk about Kodi actually translating the original YCbCr 16-235 videodata into RGB 0-255 internally, in order to composite it with the Kodi GUI (although there doesn't seem to be a consensus about whether this happens on the RPi 3 specifically, or whether Kodi 17 or 18 works the same way as earlier versions in that respect). If that's true, then setting the output colour space to YCbCr, and particularly setting it to YCbCr 16-235, is actually going to introduce a second colour space transformation, and further corrupt the video data, and outputting RGB 0-255 is likely to look better.

Does anyone know, definitively, whether Kodi 17 or 18 on the Raspberry Pi 3 actually does this?

And, in general, I welcome any thoughts on how to get the absolute minimum possible colour space translations across the entire pipeline.
Reply
#2
We do publish the source code you know Smile
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#3
(2017-11-11, 23:33)nickr Wrote: We do publish the source code you know Smile
Yeah, well, I'm a Smalltalk programmer, I struggle a bit with C. It probably feels much the same way as you would feel having to plough though pages and pages of Assembler. Smile
Reply
#4
You get double scaling and non reference quality on all the Android boxes, and also when running these Android boxes with only LE.

AFAIK you can get reference quality only with Intel at this point. (Well, also Nvidia in a way, but it's hacky and not supported by most TV brands)
Reply
#5
(2017-11-12, 02:22)Soli Wrote: (Well, also Nvidia in a way, but it's hacky and not supported by most TV brands)
You mean the Nvidia Shield TV? (I own one of those too). If so, can you link me to a description of the thing you're talking about...?
Reply
#6
(2017-11-12, 02:29)Shasarak Wrote:
(2017-11-12, 02:22)Soli Wrote: (Well, also Nvidia in a way, but it's hacky and not supported by most TV brands)
You mean the Nvidia Shield TV? (I own one of those too). If so, can you link me to a description of the thing you're talking about...?

No, Nvidia GPU. (Including the Apple TV1 running Linux). Ultimately, we don't get *actual* reference quality since YCC is being converted to RGB and in some cases we do get the wrong values because of rounding errors, but they aren't noticeable.
Reply
#7
(2017-11-12, 01:00)Shasarak Wrote:
(2017-11-11, 23:33)nickr Wrote: We do publish the source code you know Smile
Yeah, well, I'm a Smalltalk programmer, I struggle a bit with C. It probably feels much the same way as you would feel having to plough though pages and pages of Assembler. Smile 
As someone who started studying for a BE in Electrical and Electronics in 1980, I have done plenty of assembler, and FORTH for that matter. But yeah, I would struggle! I must say I didn't even know smalltalk was still a thing!
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Reply
#8
I don't know how it is with the RPi3, but the default output of RPi2 is RGB Limited. There is hard clipping of 0-15 & 236-255. It is the same with YCbCr output. I am not sure whether the Pi3/2 supports YCbCr 4:2:2 encoding. You can get YCbCr 4:2:0 output only with HDMI 2.0 and that too only for 4K 50/60Hz. RGB and YCbCr outputs of RPi2 are pretty accurate. This is all with LibreELEC Kodi 18 Milhouse build.

The test patterns that I used for BT.601/BT.709 testing didn't work on the Pi2 for some reason. So, can't say what the Pi2 does with upscaled (720p/1080p) NTSC videos.
Reply
#9
(2017-11-12, 06:49)nickr Wrote:
(2017-11-12, 01:00)Shasarak Wrote:
(2017-11-11, 23:33)nickr Wrote: We do publish the source code you know Smile
Yeah, well, I'm a Smalltalk programmer, I struggle a bit with C. It probably feels much the same way as you would feel having to plough though pages and pages of Assembler. Smile 
As someone who started studying for a BE in Electrical and Electronics in 1980, I have done plenty of assembler, and FORTH for that matter. But yeah, I would struggle! I must say I didn't even know smalltalk was still a thing!
Smalltalk is far too awesome ever to die:
https://insights.stackoverflow.com/surve...-languages

Joking aside, I can actually follow C perfectly well, but a proper answer to my question requires knowledge not just of the application but of the underlying OS, and the interaction between application, OS, and video driver, and that is definitely outside my area of expertise. Sad
Reply
#10
(2017-11-14, 08:46)wesk05 Wrote: I don't know how it is with the RPi3, but the default output of RPi2 is RGB Limited. There is hard clipping of 0-15 & 236-255. It is the same with YCbCr output. I am not sure whether the Pi3/2 supports YCbCr 4:2:2 encoding. You can get YCbCr 4:2:0 output only with HDMI 2.0 and that too only for 4K 50/60Hz. RGB and YCbCr outputs of RPi2 are pretty accurate. This is all with LibreELEC Kodi 18 Milhouse build.

The test patterns that I used for BT.601/BT.709 testing didn't work on the Pi2 for some reason. So, can't say what the Pi2 does with upscaled (720p/1080p) NTSC videos.
Well, let's not get into upscaling issues in this thread; that's a level of complication we can do without here. Smile

If above-white and below-black are being clipped, that suggests that at *some* point the original limited-range YCbCr is being remapped to full-range. (I gather from other threads that Kodi does indeed work in RGB internally, although full vs limited is a bit less clear).

If it is working in RGB full, does that mean we can avoid a second transformation by setting the output to RGB full rather than RGB limited? Or does that just make it convert to limited and then back to full again?
Reply
#11
I guess an important question here is: "Where is the 'Limited Color Range' setting?" It's present in Windows Kodi, but doesn't seem to exist in the RPi version.
Reply
#12
(2017-11-14, 10:12)Shasarak Wrote: If above-white and below-black are being clipped, that suggests that at *some* point the original limited-range YCbCr is being remapped to full-range. (I gather from other threads that Kodi does indeed work in RGB internally, although full vs limited is a bit less clear).
If it is working in RGB full, does that mean we can avoid a second transformation by setting the output to RGB full rather than RGB limited? Or does that just make it convert to limited and then back to full again? 
It clips and scales/remaps in RGB full mode (16 -> 0, 235 ->255, everything below 16 and above 235 from the original video is lost).
Reply
#13
(2017-11-14, 19:34)wesk05 Wrote:
(2017-11-14, 10:12)Shasarak Wrote: If above-white and below-black are being clipped, that suggests that at *some* point the original limited-range YCbCr is being remapped to full-range. (I gather from other threads that Kodi does indeed work in RGB internally, although full vs limited is a bit less clear).
If it is working in RGB full, does that mean we can avoid a second transformation by setting the output to RGB full rather than RGB limited? Or does that just make it convert to limited and then back to full again? 
It clips and scales/remaps in RGB full mode (16 -> 0, 235 ->255, everything below 16 and above 235 from the original video is lost).
That's a pity.

But, given that it does that, my previous question stands: wouldn't we get better output by setting the Pi to output RGB full rather than RGB limited? (And if not, why not?)
Reply
#14
The Raspberry Pi by default gets the colour space from the edid of the monitor/TV if connected via HDMI of course.

You can check the current colour space/pixel encoding used by running:
Code:
tvservice -s

You can force the pixel encoding mode by adding one of the following lines to /boot/config.txt
Code:
hdmi_pixel_encoding=0 default (limited for CEA, full for DMT)
hdmi_pixel_encoding=1 RGB limited (16-235)
hdmi_pixel_encoding=2 RGB full ( 0-255)
hdmi_pixel_encoding=3 YCbCr limited (16-235)
hdmi_pixel_encoding=4 YCbCr full ( 0-255)

More info here:
https://elinux.org/RPiconfig
Reply
#15
Thank you, rascas, but I was aware of most of that. Smile What I'm interested in is not "how do you change the colour space?" it's "which colour space gives you the best image quality, and why?'
Reply

Logout Mark Read Team Forum Stats Members Help
Best output colour space, and how to achieve it...?0