Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cocoa-cb: add support for macOS color space transformation (EDR/HDR) #14017

Merged
merged 1 commit into from May 5, 2024

Conversation

Akemi
Copy link
Member

@Akemi Akemi commented Apr 28, 2024

up to date version of #8485, with some added new colour spaces. also only for cocoa-cb since it's not necessary for the macvk vulkan backend or rather would break it.

this will most likely be the last new feature for the cocoa-cb/libmpv/opengl backend from me. just wanted to add this already done feature that was resting for years.

it might come in handy for future backends though.

Fixes #7341

Copy link

github-actions bot commented Apr 28, 2024

Download the artifacts for this pull request:

Windows
macOS

@Akemi Akemi force-pushed the cocoa_cb_hdr branch 2 times, most recently from 271285c to a1db286 Compare April 28, 2024 21:34
@Akemi
Copy link
Member Author

Akemi commented Apr 28, 2024

on macOS 12 + Xcode 13.1 + SDK 12. can't find 2 of the 4 colour spaces introduced in 12.0, indicating an SDK problem
https://developer.apple.com/documentation/coregraphics/cgcolorspace/4010583-itur_709_hlg
https://developer.apple.com/documentation/coregraphics/cgcolorspace/3892091-itur_709_pq
https://developer.apple.com/documentation/coregraphics/cgcolorspace/3867016-lineardisplayp3
https://developer.apple.com/documentation/coregraphics/cgcolorspace/3867017-linearitur_2020

Message: Detected macOS sdk path: /Applications/Xcode_13.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk
Message: Detected macOS SDK: 12.0

--------------------------------------------------------------------------------------

../video/out/cocoa_cb_common.swift:164:79: error: type 'CGColorSpace' has no member 'itur_709_HLG'
            case MAC_CSP_ITUR_709_HLG: return CGColorSpace(name: CGColorSpace.itur_709_HLG)
                                                                 ~~~~~~~~~~~~ ^~~~~~~~~~~~
../video/out/cocoa_cb_common.swift:165:78: error: type 'CGColorSpace' has no member 'itur_709_PQ'
            case MAC_CSP_ITUR_709_PQ: return CGColorSpace(name: CGColorSpace.itur_709_PQ)
                                                                ~~~~~~~~~~~~ ^~~~~~~~~~~

on macOS 12 + Xcode 14.2 + SDK 13.1. no building problems but following runtime error, indicating a general problem with those two new colour spaces and macOS 12 + CoreGraphic (framework version 12)

Message: Detected macOS sdk path: /Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk
Message: Detected macOS SDK: 13.1

--------------------------------------------------------------------------------------

dyld[8493]: Symbol not found: (_kCGColorSpaceITUR_709_HLG)
  Referenced from: '/Users/runner/work/mpv/mpv/build/mpv'
  Expected in: '/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics'
./ci/build-macos.sh: line 25:  8493 Abort trap: 6           ./build/mpv -v --no-config

on macOS 13 + Xcode 14.2 + SDK 13.1 (same setup as second test), there are no problems regarding those colour spaces, indicating a problem with macOS 12 as a platform.

removing the two affected colour spaces on macOS 12 + Xcode 14.2 + SDK 13.1 shields no problems.

TLDR macOS 12 has a CoreGraphics framework issue, macOS SDK 12 is broken for those two colour spaces. the latest SDK available on macOS 12 is SDK 13, that fixes the build problems but not the runtime crash. is fixed with SDK 13 and macOS 13. to fix this, we can't just guard those two colour spaces with a build time and runtime check for macOS+SDK 13, since the symbol not found crash will still occur. for now i will just remove those two (undocumented) colour spaces.

i had similar issues with colour spaces introduced in macOS 10.14.6.

build tests for reference:
https://github.com/mpv-player/mpv/actions/runs/8870240999/job/24351805621?pr=14017
https://github.com/mpv-player/mpv/actions/runs/8870240999/job/24351805695?pr=14017
https://github.com/mpv-player/mpv/actions/runs/8870555909/job/24352474494?pr=14017

DOCS/man/options.rst Outdated Show resolved Hide resolved
@KTamas
Copy link

KTamas commented Apr 29, 2024

oh my god I'm so excited about this one

meson.build Show resolved Hide resolved
DOCS/man/options.rst Outdated Show resolved Hide resolved
DOCS/man/options.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@kasper93 kasper93 left a comment

Choose a reason for hiding this comment

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

Not tested, but looks ok.

@KTamas
Copy link

KTamas commented May 1, 2024

Not sure this is working? Compiled this version just now. FIle is proven to be a proper HDR video when remuxed to MP4 for QuickTime, I use it as my test file for ages, It is streamed from the internet, my config is below. Works with IINA although IINA's HDR colors are completely wrong and way too dark compared to QuickTime.

Pretty sure video doesn't activate HDR (I'd see the brightness change) on the other hand it does look way too dark the same way IINA does.

M1 Pro mac, built-in display.

macos-fs-animation-duration=0
ontop
ontop-level=window
window-scale=0.3
demuxer-max-bytes=4096MiB
demuxer-max-back-bytes=2048MiB
screenshot-format=jpg
screenshot-high-bit-depth=no
screenshot-directory=/Users/redacted/Desktop
save-position-on-quit
screenshot-tag-colorspace=yes
profile=fast

Screenshot 2024-05-01 at 6 15 42 PM

@Akemi
Copy link
Member Author

Akemi commented May 1, 2024

this is for cocoa-cb/libmpv and not vo=gpu(-next). you are using the macvk backend.

also only for cocoa-cb since it's not necessary for the macvk vulkan backend or rather would break it.

[edit]
macvk already supports this automatically with --target-colorspace-hint.

@KTamas
Copy link

KTamas commented May 1, 2024

Right, my bad. Forced it to libmpv, however HDR is still not activated? Maybe I'm still doing something wrong. It's more apparent to the eyes but this is a screenshot with IINA on the left and MPV on the right, and even the screenshot shows the brightness difference.

image

@Akemi
Copy link
Member Author

Akemi commented May 1, 2024

i am not sure how i should help you? you neither provide a log nor did you tell us what options you used for testing. if you expect HDR to work automatically, then that's now what this does. you have to manually specify the right csp like mentioned.

@eko5624
Copy link

eko5624 commented May 1, 2024

I want to test on my intel macbookpro 2017, what's the right csp? How to write mpv.conf, just like:

vo=libmpv
cocoa-cb-output-csp=?
target-trc=?
target-prim=?

@Akemi
Copy link
Member Author

Akemi commented May 1, 2024

i can't really tell. it depends on your hardware and display characteristics. though that is mentioned in the documentation.

also this PR is probably the wrong place for discussing this. you should rather open a discussion.

@KTamas
Copy link

KTamas commented May 2, 2024

fwiw I managed to get some HDR working by playing around with those parameters (it looked wrong, but it was HDR), so in that sense I can confirm it working. Appreciate the help.

@Akemi
Copy link
Member Author

Akemi commented May 5, 2024

i tested it some more on my TV and it also seems to work properly when setup/configured correctly.

i might write up something in the wiki how to configure everything correctly in the future. though still need to test quite a lot still.

by default utilises the color space of the screen on which the window is
located. if a specific value is defined, it will instead be utilised.

depending on the chosen color space the macOS EDR (HDR) support is
activated and that OS's transformation (tone mapping) is used.

Fixes mpv-player#7341
@Akemi Akemi merged commit 8a61929 into mpv-player:master May 5, 2024
17 checks passed
@Akemi Akemi deleted the cocoa_cb_hdr branch May 5, 2024 17:03
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.

utilise macOS HDR/EDR functionality
4 participants