Replies: 4 comments 48 replies
Before I read this, could you retest with mpv and libplacebo built from master. There were significant changes to all this in not yet released builds. |
|
For wayland+KDE, to allow full color management pipeline:
|
It does accept custom primaries as metadata. You still need encoding primaries, you cannot just encode free-form values into free-from buffer, because nothing will understand that, even with metadata. It's not how the things work. Find better LLM, because I will not spend time explain this against some hallucinating ideas of LLM.
Technically, it's correct, after intersecting two triangles, you may end up with poligon with more sides. But this is completely irrelevant. The question you want to answer, is where is the RED primary. What value is the pure RED? It cannot be a line or multiple points, it's single point. If your red primary is outside the bt.2020 encoding, than it cannot be used and we clamp to the intersection of the most saturated red that can be represented. Such that the colors that are outside the bt.2020 encoding are gamut mapped to fit inside. Specific case, which would happen when you don't perform gamut mapping and instead convert [1, 0, 0] display-p3 to bt.2020, you get [0.753833, 0.045744, -0.001210], see that there is negative value here? We cannot send negative value over the HDMI, would you agree? So regardless what we need to clip or gamut map it. And we do that by fitting the colorspace into the triangle that is defined inside encoding colorspace.
It shouldn't be. I don't know what you want to achieve. You are looking at the numbers, which you don't understand, how they are produced and how they are used, and complain that they are incorrect? Could you step back a little and focus on actual issue? Please provide examples where produced image by mpv is incorrect, the image, not "numbers" and then we can discuss. |
Yes, standards.
You, argued, that your colorspace is not triangle. So, this is the main question. How do you imagine this to work? We are working with RGB colorspace, it has 3 primaries, which can produce various colors by varying the intensity of them. Colorspace therefore is a triangle.
Again, how it can be avoided? You seem to be very sure that it can be avoided. I don't know how and when I asked you, you said "I am not looking for the answer to this question". So, I'm not sure how can we continue.
Clamping like that will skew hue, we have way more advanced gamut mapping than clamping. Additionally your proposal is clamping to P3 first which is smaller than bt.2020, and later clamping to bt.2020 again. Anyway, if you reverse order you would get inverse situation. But either way, what you end up in the end is a TRIANGLE that is your final colorspace. The fact you clamp twice is inconsequential, you arrive at the RGB colorspace which is triangle. Basically you can imagine that you do the clamping and get effective triangle, and this is what is shown in mpv stats page. I think you are close to understanding that, you realized that you need to clamp twice, which basically produces triangle that is intersection of those two. |
Uh oh!
There was an error while loading. Please reload this page.
Please allow me to share some observations regarding SDR content playback in mpv, its configuration settings, and the interaction with Wayland.
My system setup is a laptop running an up-to-date Fedora 44 with KDE and Wayland, an Intel CPU with integrated GPU, and up-to-date Mesa, Intel Media Drivers, FFmpeg, and mpv 0.41. The laptop display features a near-P3 D65 color gamut and a native transfer function close to a pure 2.2 gamma. Therefore, I consider the options target-prim=display-p3 and target-trc=gamma2.2 to be a reasonably acceptable approximation of the display's capabilities (along with target-contrast=1200 close to specs and tests and treat-srgb-as-power22=no to properly distinguish the sRGB EOTF from pure gamma 2.2). This is a rather typical, common configuration without any exotic specifics. The core options of my mpv config are as follows:
vo=gpu-next
gpu-api=vulkan
hwdec=vulkan,vaapi
gpu-context=waylandvk
Since most SDR video content is encoded with BT.709 primaries and a BT.1886 EOTF, it needs to be adapted for correct playback on my laptop (accurate to the specified approximation)—both the color space from BT.709 to Display P3 D65, and the EOTF from BT.1886 to pure gamma 2.2. Thus, the "ideal pipeline" of transformations should look like this:
data encoded with BT.709 primaries and inverse BT.1886 EOTF -> forward BT.1886 EOTF -> from BT.709 to Display P3 D65 transformation -> inverse pure gamma 2.2 -> display with forward pure gamma 2.2
It seems that this is exactly what I can achieve by configuring mpv according to Option A.
Option A:
target-colorspace-hint=no
target-contrast=1200
target-prim=display-p3
target-trc=gamma2.2
treat-srgb-as-power22=no
mpv stats info:
In this specific case, I can be certain that mpv correctly performs both transformations—both the color space conversion (preventing oversaturation in reds and greens, which happens when BT.709 content is mapped directly onto a P3 display without conversion) and the transfer function mapping. This is indeed confirmed by the visual result. So, the pipeline looks roughly like this:
data encoded with BT.709 primaries and inverse BT.1886 EOTF -> mpv applies forward BT.1886 EOTF -> mpv applies from BT.709 to Display P3 D65 transformation -> mpv applies inverse pure gamma 2.2 -> Wayland has nothing to do -> display with forward pure gamma 2.2
For sRGB content, it would map accordingly:
data encoded with BT.709 primaries and inverse piecewise sRGB EOTF -> mpv applies forward piecewise sRGB EOTF -> mpv applies from BT.709 to Display P3 D65 transformation -> mpv applies inverse pure gamma 2.2 -> Wayland has nothing to do -> display with forward pure gamma 2.2
Option A seems ideal, but it has its downsides—specifically, I cannot assign a display ICC profile in the operating system's Display Configuration in this case. Option A works perfectly when mpv handles all transformations on its own, while Wayland assumes the display is a default one with BT.709 primaries and an sRGB EOTF, thereby passing the processed data from mpv directly to the display without further alterations. However, if I add the display's ICC profile (P3 D65 and pure gamma 2.2) under this setup, it appears that Wayland performs an additional BT.709 to Display P3 D65 transformation, causing the colors to become undersaturated.
Nonetheless, correct reproduction can be easily achieved with an ICC profile active via Option B.
Option B:
target-colorspace-hint=yes
target-contrast=1200
target-prim=display-p3
target-trc=gamma2.2
treat-srgb-as-power22=no
mpv stats info:
The playback appears correct again at first glance, but some questions remain. First, why do the display properties now report Transfer: linear and Format: rgba16? Second, under Option B, the target-contrast=1200 option now affects not only BT.1886 content but also sRGB and any other content, and it does so quite aggressively (even though the black point in the ICC profile is a perfect zero). Under Option A, the target-contrast=1200 option only affects BT.1886 content and acts gently, exactly as intended. Third, for some reason, there is no difference between the target and source values of the target-colorspace-hint-mode option.
An interesting but unacceptable result is obtained if the target-colorspace-hint-strict=no option is added—Option C.
Option C:
target-colorspace-hint=yes
target-colorspace-hint-strict=no
target-contrast=1200
target-prim=display-p3
target-trc=gamma2.2
treat-srgb-as-power22=no
mpv stats info:
In this case, Transfer shows gamma2.2 (just like in Option A), but Format becomes rgba16 (just like in Option B). Also, there is still no difference between the target and source values of target-colorspace-hint-mode. The issue with Option C is that an inverted gamma is applied twice—presumably by both mpv and Wayland—causing the image to become catastrophically overexposed and clipped.
It is also worth noting that in my software stack, the icc-profile-auto and icc-force-contrast options have absolutely no effect in any of these cases.
Could you please advise which option is better to stick with for SDR content—Option A or Option B? Or perhaps the configuration needs to be tweaked into a different approach altogether? On one hand, with Option A, all conversions are executed solely by mpv, ensuring their high quality. On the other hand, the mpv manual states that target-colorspace-hint=<auto|yes> is highly recommended to use, which leans in favor of Option B...
Have you noticed any unintended behavior or bugs here?
Thank you.
All reactions