Skip to content

mp_image: handle XYZ, and forward to libplacebo properly#18124

Open
cyanreg wants to merge 1 commit into
mpv-player:masterfrom
cyanreg:master
Open

mp_image: handle XYZ, and forward to libplacebo properly#18124
cyanreg wants to merge 1 commit into
mpv-player:masterfrom
cyanreg:master

Conversation

@cyanreg

@cyanreg cyanreg commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

The current behaviour overrode colorspace props which caused XYZ to get incorrectly decoded.
Requires recent ffmpeg (https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23475) and libplacebo improvements (https://code.videolan.org/videolan/libplacebo/-/merge_requests/865).

The current behaviour overrode colorspace props which caused XYZ to get
incorrectly decoded.
Comment thread video/mp_image.c
// decode, and tag post-decode primaries as DCI-P3 to match what its XYZ
// handler bakes in. Don't override the TRC: linear-light XYZ keeps
// TRC=LINEAR, DCDM-encoded XYZ keeps TRC=ST428.
if (src->color_primaries == AVCOL_PRI_SMPTE428) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XYZ is almost never tagged, as such.

@ValeZAA ValeZAA Jun 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XYZ is typically «fake» tagged as Identity (Identity matrix means either BGR or YZX) and primaries of white point 1/3, 1/3, unity, and gamma 2.6. Primaries is what signals that Identity here means YZX and not BGR. DCI-P3 would be what encoding to linear RGB from XYZ NPM matrix is, I believe. FFmpeg does not preserve WCG here encoding using BT.709 NPM. New patch apparently adds support for new NPMs. So you decode YZX using 2.6 gamma and then convert to linear RGB (e.g. of P3 with DCI white NPM) and then encode with PQ or whatever. Tag it all in the end with PQ/DCI-P3.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, there is big gaps in DCDM support in ffmpeg. I made it work somehow good in mpv/libplacebo to get satisfactory rendering.

Comment thread video/mp_image.c
if (params->color.transfer == PL_COLOR_TRC_UNKNOWN)
params->color.transfer = PL_COLOR_TRC_SRGB;
// Respect an explicit XYZ system tagging
if (params->repr.sys != PL_COLOR_SYSTEM_XYZ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code, no?

mp_image_params_get_forced_csp already does:

    if (csp == PL_COLOR_SYSTEM_RGB && params->repr.sys == PL_COLOR_SYSTEM_XYZ)
        csp = PL_COLOR_SYSTEM_XYZ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants