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

HDR bug on M2/M3 chip. #4312

Open
1 task
caipod opened this issue Apr 1, 2023 · 71 comments
Open
1 task

HDR bug on M2/M3 chip. #4312

caipod opened this issue Apr 1, 2023 · 71 comments

Comments

@caipod
Copy link

caipod commented Apr 1, 2023

System and IINA version:

  • macOS 13.3 (22E252) M2 Mac mini
  • IINA 1.3.1

Expected behavior:
The player will display the right HDR effect when I switch on the HDR during playing an HDR MKV file.

Actual behavior:
I recently bought the M2 mac mini. The interface goes much much darker when I play a HDR MKV file, but when I switch off the HDR, the player displays the right HDR effect.
But this situation will not appear on the M1 mac. My Mac studio works just fine.

Crash report:

mpv log:
[   0.004][v][cplayer] mpv 0.34.1 Copyright © 2000-2021 mpv/MPlayer/mplayer2 projects
[   0.004][v][cplayer]  built on Sat May 28 15:57:18 UTC 2022
[   0.004][v][cplayer] FFmpeg library versions:
[   0.004][v][cplayer]    libavutil       56.70.100
[   0.004][v][cplayer]    libavcodec      58.134.100
[   0.004][v][cplayer]    libavformat     58.76.100
[   0.004][v][cplayer]    libswscale      5.9.100
[   0.004][v][cplayer]    libavfilter     7.110.100
[   0.004][v][cplayer]    libswresample   3.9.100
[   0.004][v][cplayer] FFmpeg version: 4.4.2
[   0.004][v][cplayer] 
[   0.004][v][cplayer] Configuration: waf configure --prefix=/opt/homebrew/Cellar/mpv-iina/0.34.1 --enable-javascript --enable-libmpv-shared --enable-lua --enable-libarchive --enable-uchardet --enable-libbluray --disable-swift --disable-debug-build --disable-macos-media-player --confdir=/opt/homebrew/etc/mpv --datadir=/opt/homebrew/Cellar/mpv-iina/0.34.1/share/mpv-iina --mandir=/opt/homebrew/Cellar/mpv-iina/0.34.1/share/man --docdir=/opt/homebrew/Cellar/mpv-iina/0.34.1/share/doc/mpv-iina --lua=luajit
[   0.004][v][cplayer] List of enabled features: asm bsd-fstatfs build-date cocoa coreaudio cplayer cplugins ffmpeg ffmpeg-aviocontext-bytes-read gl gl-cocoa glob glob-posix gpl iconv javascript jpeg lcms2 libarchive libass libavdevice libbluray libdl libm libmpv-shared lua luajit macos-10-11-features macos-10-12-2-features macos-10-14-features macos-touchbar optimize osx-thread-name plain-gl posix posix-or-mingw pthreads rubberband stdatomic uchardet vector videotoolbox-gl videotoolbox-hwaccel zimg zlib
[   0.004][v][cplayer] mpv 0.34.1 Copyright © 2000-2021 mpv/MPlayer/mplayer2 projects
[   0.004][v][cplayer]  built on Sat May 28 15:57:18 UTC 2022
[   0.004][v][cplayer] FFmpeg library versions:
[   0.004][v][cplayer]    libavutil       56.70.100
[   0.004][v][cplayer]    libavcodec      58.134.100
[   0.004][v][cplayer]    libavformat     58.76.100
[   0.004][v][cplayer]    libswscale      5.9.100
[   0.004][v][cplayer]    libavfilter     7.110.100
[   0.004][v][cplayer]    libswresample   3.9.100
[   0.004][v][cplayer] FFmpeg version: 4.4.2
[   0.004][v][cplayer] 
[   0.004][v][cplayer] Configuration: waf configure --prefix=/opt/homebrew/Cellar/mpv-iina/0.34.1 --enable-javascript --enable-libmpv-shared --enable-lua --enable-libarchive --enable-uchardet --enable-libbluray --disable-swift --disable-debug-build --disable-macos-media-player --confdir=/opt/homebrew/etc/mpv --datadir=/opt/homebrew/Cellar/mpv-iina/0.34.1/share/mpv-iina --mandir=/opt/homebrew/Cellar/mpv-iina/0.34.1/share/man --docdir=/opt/homebrew/Cellar/mpv-iina/0.34.1/share/doc/mpv-iina --lua=luajit
[   0.004][v][cplayer] List of enabled features: asm bsd-fstatfs build-date cocoa coreaudio cplayer cplugins ffmpeg ffmpeg-aviocontext-bytes-read gl gl-cocoa glob glob-posix gpl iconv javascript jpeg lcms2 libarchive libass libavdevice libbluray libdl libm libmpv-shared lua luajit macos-10-11-features macos-10-12-2-features macos-10-14-features macos-touchbar optimize osx-thread-name plain-gl posix posix-or-mingw pthreads rubberband stdatomic uchardet vector videotoolbox-gl videotoolbox-hwaccel zimg zlib
[   0.004][d][global] config path: '' -> '-'
[   0.004][d][global] user path: '~~home/' -> ''
[   0.004][d][global] user path: '~~old_home/' -> ''
[   0.004][d][global] user path: '/Applications/IINA.app/Contents/Resources/config/iina-default-input.conf' -> '/Applications/IINA.app/Contents/Resources/config/iina-default-input.conf'
[   0.004][v][bdmv/bluray] Opening /Applications/IINA.app/Contents/Resources/config/iina-default-input.conf
[   0.004][v][file] Opening /Applications/IINA.app/Contents/Resources/config/iina-default-input.conf
[   0.004][d][file] resize stream to 131072 bytes, drop 0 bytes
[   0.004][d][file] Stream opened successfully.
[   0.004][v][input] Parsing input config file /Applications/IINA.app/Contents/Resources/config/iina-default-input.conf
[   0.004][v][input] Input config file /Applications/IINA.app/Contents/Resources/config/iina-default-input.conf parsed: 69 binds
[   0.004][d][global] user path: '/Users/caipodm2/Library/Logs/com.colliderli.iina/2023-04-01-21-18-17_6uYbO8/mpv.log' -> '/Users/caipodm2/Library/Logs/com.colliderli.iina/2023-04-01-21-18-17_6uYbO8/mpv.log'
[   0.004][d][ytdl_hook] Loading lua script @ytdl_hook.lua...
[   0.004][d][stats] Loading lua script @stats.lua...
[   0.004][d][console] Loading lua script @console.lua...
[   0.004][d][auto_profiles] Loading lua script @auto_profiles.lua...
[   0.004][d][osx] Exiting...
[   0.004][d][ytdl_hook] loading mp.defaults
[   0.004][d][console] loading mp.defaults
[   0.004][d][stats] loading mp.defaults
[   0.005][v][cplayer] Set property: vo="libmpv" -> 1
[   0.005][v][cplayer] Set property: keepaspect="no" -> 1
[   0.005][v][cplayer] Set property: gpu-hwdec-interop="auto" -> 1
[   0.005][d][auto_profiles] loading mp.defaults
[   0.005][d][ytdl_hook] loading @ytdl_hook.lua
[   0.005][d][stats] loading @stats.lua
[   0.005][d][console] loading @console.lua
[   0.005][d][auto_profiles] loading @auto_profiles.lua
[   0.005][d][ytdl_hook] reading options for ytdl_hook 
[   0.005][d][ytdl_hook] script-opts/ytdl_hook.conf not found. 
[   0.005][d][ytdl_hook] lua-settings/ytdl_hook.conf not found. 
[   0.006][d][stats] reading options for stats 
[   0.006][d][stats] script-opts/stats.conf not found. 
[   0.006][d][stats] lua-settings/stats.conf not found. 
[   0.031][v][ao/coreaudio] selected audio output device:  (49)
[   0.032][d][console] reading options for console 
[   0.032][d][console] script-opts/console.conf not found. 
[   0.032][d][console] lua-settings/console.conf not found. 
[   0.032][v][cplayer] Waiting for scripts...
[   0.032][d][auto_profiles] Exiting...
[   0.032][d][osd/libass] ASS library version: 0x1502000 (runtime 0x1502000)
[   0.032][v][osd/libass] libass API version: 0x1502000
[   0.032][v][osd/libass] libass source: tarball: 0.15.2
[   0.032][v][osd/libass] Shaper: FriBidi 1.0.12 (SIMPLE) HarfBuzz-ng 4.2.1 (COMPLEX)
[   0.032][v][osd/libass] Setting up fonts...
[   0.033][v][osd/libass] Using font provider coretext
[   0.033][v][osd/libass] Done.
[   0.033][d][cplayer] Run command: define-section, flags=64, args=[name="input_stats", contents="", flags="default"]
[   0.033][d][cplayer] Run command: enable-section, flags=64, args=[name="input_stats", flags="allow-hide-cursor+allow-vo-dragging"]
[   0.033][d][cplayer] Run command: define-section, flags=64, args=[name="input_forced_stats", contents="", flags="force"]
[   0.033][v][cplayer] Done loading scripts.
[   0.034][d][cplayer] Run command: define-section, flags=64, args=[name="input_console", contents="", flags="default"]
[   0.034][d][cplayer] Run command: enable-section, flags=64, args=[name="input_console", flags="allow-hide-cursor+allow-vo-dragging"]
[   0.034][d][cplayer] Run command: define-section, flags=64, args=[name="input_forced_console", contents="", flags="force"]
[   0.034][d][cplayer] Run command: enable-section, flags=64, args=[name="input_forced_console", flags="allow-hide-cursor+allow-vo-dragging"]
[   0.034][d][cplayer] Run command: enable-section, flags=64, args=[name="input_forced_stats", flags="allow-hide-cursor+allow-vo-dragging"]


Steps to reproduce:

  • MPV does not have this problem.

How often does this happen?
Everytime
mpv.log

@low-batt
Copy link
Contributor

low-batt commented Apr 1, 2023

This sounds like a duplicate of issue #4214, except I have not heard anyone report this before:

but when I switch off the HDR, the player displays the right HDR effect.

Not sure what to make of that. If you enable HDR and then follow this workaround mentioned in issue #3906 does the dimming stop?:

Go to IINA menubar -> Video -> Crop -> Custom... -> Press the Cancel button in the right bottom corner

HDR was working fine on the M1 under macOS Monterey. The problem appeared on the M1 with the release of macOS Ventura. For this reason we have been assuming the problem is due to a defect in macOS. We were hoping 13.3 would have a fix for this, but the problem is still present.

In IINA 1.3.1 a horrible hackaround was added that so far as been effective in suppressing the dimming behavior on the M1.

The situation is different on the M2. On the M1 the problem only occurs in full screen mode. I'm hearing that is not true on the M2. So the problem is worse on the M2. It is very strange that the sequence shown above works to suppress the problem on the M2. As I do not have a Mac with the M2 chip I've not been able to look into what specifically it is about that sequence that causes the dimming to stop.

@caipod
Copy link
Author

caipod commented Apr 1, 2023

Your instruction works temporary. I quit the app and re-open it , the dimming problem shows again.

@low-batt
Copy link
Contributor

low-batt commented Apr 1, 2023

Unfortunately that is the expected behavior with that workaround.

@caipod
Copy link
Author

caipod commented Apr 1, 2023

I can help you with testing the HDR problem in the coming betas on my M2 mac if you want.🧑🏻‍💻

@low-batt
Copy link
Contributor

low-batt commented Apr 2, 2023

I really appreciate the offer of help with testing!!

In general, until the definitive root cause of a software problem is identified you can't be absolutely certain of the responsible code. But as HDR was working on the M1 until macOS Ventura we strongly suspect the problem resides in macOS. The M2 behavior also points to macOS as (that I know of) IINA and its dependencies do not contain any code that changes behavior based on the chip it is running on. So we are expecting Apple has to fix this problem.

With the M1 we noticed the dimming would stop when the OSC was displayed. @royj prepared what software developers refer to as a hackaround based on the knowledge that for reasons unknown macOS did not dim the screen if another view (the OSC) was present. The "hackaround" mimics that condition adding a tiny nearly invisible view. This is usually termed a hackaround rather than a workaround as we can't explain from a detailed technical perspective how this works around the problem. And therefore we can't be assured that this hackaround will continue to work in future versions of macOS.

The situation is similar with the M2 in that we have a workaround of invoking and canceling the crop operation. That suggests that maybe we could come up with a similar "hackaround" as was done for the M1. To do that a developer would need to be able to pull apart the crop code and identify what part of it suppresses the dimming. Doing that requires an iterrative process of changing code and testing the effect on the dimming. That must be done on a Mac with the M2 chip.

So we need some developer with a M2 Mac to see if a reasonable hackaround can be developed for the M2.

Other than that we are waiting for Apple to fix macOS.

@vazome
Copy link

vazome commented Apr 2, 2023

Same M2 Air

@asciibeats
Copy link

Yep, M2 Air too

@GST-Main
Copy link

M2 Pro too. It seems such a challenging job. I really wanna participate in the solving this problem (I LOVE HDR 😉). I'm not that good at developing, but I can offer you testing in m2 pro or some analysis in your request. I'm new to co-operating github project, so could you tell me how can I participate in and what can I do for you.

@low-batt
Copy link
Contributor

@GST-Main I really appreciate the offer of help with testing.

Caught me busy this weekend with non-IINA stuff, so this is a rushed reply, which I always hate doing as I usually get something wrong when I rush, but lets's blunder ahead…

I do not work on IINA's HDR code, it is outside of my area of expertise. I'm involved because my development machine is a MacBookPro18,2 with a XDR display, allowing me to test HDR. I also help when needed with code merges in this area.

I just ran a quick test and did not get the results I expected. I played the HDR video
The World in HDR in 4K (ULTRA HD) using IINA 1.3.0, went into full screen mode and waited for the OSC to hide. The screen went dim. This was run under the latest macOS release, 13.3.1.

I then commented out the hack around that was added to IINA 1.3.1 here that suppresses the problem on the M1. I built the latest IINA sources from the develop branch and repeated the test. The screen did not dim.

If there is anyone reading this with a M2 machine who knows how to deal with an unsigned nightly build can you please test the latest build found here and see if the dimming still occurs when running on a M2.

The develop branch contains a fix for the HDR issue #3772. Normally I'd perform some more testing so I could report exactly what is happening. I'd pull that change and test again to confirm that fix is responsible for the change in behavior. Sorry, no time this weekend to run that test.

Hopefully someone can test the nightly build on a M2 Mac and see if the behavior has changed on the M2 as well.

@GST-Main
Copy link

I tested the latest build (commit 869eaaf) in your link in Macbook Pro 16" M2 Pro with MacOS 13.2.1(22D68). The screen does not dim. I can't wait this change come out to official release. If you need any more help, feel free to tell me.

@low-batt
Copy link
Contributor

@GST-Main Thanks for testing the nightly build. Very interesting result.

I ran the following test today. Using the develop branch I commented out the workaround in MainWindowController for the problem on the M1. I then backed out the changes added in PR #4174. With those changes removed the dimming when playing a HDR video in full screen mode on the M1 was back.

This confirms the changes made in PR #4174 have suppressed the dimming problem on both the M1 and the M2. @OceanS2000, @CarterLi any thoughts on how these changes corrected the strange dimming problem?

@GST-Main I will ask for more help with testing on the M2 when we are closer to release. Developers are currently working to produce upgraded dependencies including mpv 0.35.1 and FFmpeg 5.2.1. Once the nightly build includes the upgrading dependencies we will want to test again to make sure nothing has changed and HDR is still working.

I'm going to do some more testing but this seems to mean I can remove the M1 workaround in MainWindowController.windowDidLoad.

@GST-Main
Copy link

@low-batt OK. I'll be waiting.

@caipod
Copy link
Author

caipod commented Apr 17, 2023

This version [8bdf01c] works just fine. The HDR dimming problem has gone.
I played an local MKV HDR file and toggled HDR switch, the screen got brighter. The color is also good.
My device is M2 mac mini base version.

@johnvonneumann36
Copy link

I have met the same problem with m2 macbook pro. I have tested it in some ways and I want to provide more information on this problem. There are two ways I found that can barely see the effect expected:

  1. Open via another video player (vlc in my case) and iina just works fine even you pause in vlc.
  2. Swipe up with four fingers to open Mission Control. The video shall be played right as expected.

I suppose this problem is caused by some system problem such as stage manager.

@low-batt
Copy link
Contributor

Thanks for the additional information about the behavior on the M2. You never really know which component is responsible for a software problem until you track down the actual root cause of the problem and can explain why it triggered the behavior seen.

Usually with software if you upgrade a component and a problem appears, it is due to a defect in the upgraded component. However it could be that another component was doing something that was invalid and by luck was to able to get away with it until the upgraded component just happened to expose the problem.

In the case at hand HDR was working fine on the M1 under macOS Monterey. The problem appeared with the upgrade to macOS Ventura. Other graphics problems not related to IINA have been reported against Ventura. I'm still hearing reports of black screens with macOS 13.3.1. That the behavior differs greatly on the M2 is also suggestive of a problem in macOS as the behavior should be consistent.

From the Apple Newsroom article macOS Ventura is now available:

macOS Ventura brings new technologies like Metal 3 that take full advantage of the incredible hardware in Mac

That is referring to Apple's Metal graphics API. So we know Ventura includes a major upgrade to graphics.

All this is strongly suggestive that these odd behaviors are due to problems in the graphics portion of macOS.

Hopefully all graphics related regressions will be fixed in macOS Ventura 13.4.

@asciibeats
Copy link

Thank you for your insight, very much appreciated

@zziilii
Copy link

zziilii commented Apr 23, 2023

期待早日修复,iina 是用过最好的mac播放器,但是这个问题最近开始困扰我了

@Kaivinstudy
Copy link

After my testing the latest version #52708e7 was able to dog in my MacBook pro M2 MAX to solve the HDR problem.

@low-batt
Copy link
Contributor

The latest unsigned nightly build found here has been built with upgraded dependencies including mpv 0.35.1 and FFmpeg 6.0. It also contains a new tone mapping setting in the Video/Audio tab of the settings panel. These are major changes. Those of you who have been testing these development builds on the M2, if you have time please confirm HDR on the M2 is still not showing the dimming problem.

@GST-Main These are the changes I was having you wait for before testing again.

@DiksonH
Copy link

DiksonH commented Apr 23, 2023

The latest unsigned nightly build found here has been built with upgraded dependencies including mpv 0.35.1 and FFmpeg 6.0. It also contains a new tone mapping setting in the Video/Audio tab of the settings panel. These are major changes. Those of you who have been testing these development builds on the M2, if you have time please confirm HDR on the M2 is still not showing the dimming problem.

@GST-Main These are the changes I was having you wait for before testing again.

I have just tried the 52708e7 commit version. Tested multiple HDR videos, dimming problem is fixed.
I am using a M2 pro macbook pro.

@GST-Main
Copy link

The latest unsigned nightly build found here has been built with upgraded dependencies including mpv 0.35.1 and FFmpeg 6.0. It also contains a new tone mapping setting in the Video/Audio tab of the settings panel. These are major changes. Those of you who have been testing these development builds on the M2, if you have time please confirm HDR on the M2 is still not showing the dimming problem.

@GST-Main These are the changes I was having you wait for before testing again.

I tested 52708e7 version and there's no dimming.

However, I don't know the tone mapping setting actually works. It seems to be a feature that makes a SDR video like a HDR video by tone mapping, but when I tried with some SDR videos (and also HDR videos) by turning on and off and changing peek brightness setting, it seems there's no changes.

Can I ask you that this is a right way to test new tone mapping setting, what is the effect exactly and how I can use it?

@low-batt
Copy link
Contributor

Thanks everyone for testing!

On this:

Can I ask you that this is a right way to test new tone mapping setting, what is the effect exactly and how I can use it?

First I probably should have mentioned IINA needs to be restarted after changing the tone mapping settings for the new value to take effect.

Remember I am not doing the HDR work, merely helping merge and testing. For how this relates to SDR, I'm hoping @CarterLi will comment on that.

With respects to HDR, it depends upon the video being played. From High-dynamic-range television:

SDR formats are able to represent a maximum luminance level of around 100 nits. For HDR, this number increases to around 1,000–10,000 nits

The XDR screens in the latest MacBook Pros can handle 1000 nits. But if you tried to play a video that was encoded such that the dynamic range goes up to 10000 nits it would need to be tone mapped to stay within the range of the XDR display.

Some of the effects are subtle. You have to look close at scenes that use the full dynamic range. To really confirm tone mapping is occurring we can exaggerate the effects for a test.

First:

  • Start IINA and open the Video/Audio settings
  • Set Target peak to 50
  • Set Algorithm to clip
  • Restart IINA

Then:

  • Play The World in HDR in 4K (ULTRA HD)
  • Stop at around 00:18 when the two sliver jets are being shown
  • Notice how blown out and messed up the rear jet looks
  • Open the Video/Audio settings
  • Set Target peak to 0
  • Set Algorithm to auto
  • Restart IINA

Now:

@CarterLi
Copy link
Contributor

CarterLi commented Apr 25, 2023

For how this relates to SDR, I'm hoping @CarterLi will comment on that.

Nothing related. SDR videos have low maximum brightness and don't need to be tone mapped.

In addition, for HDR videos, if the maximum brightness used by the video source is lower than the maximum brightness of your monitor supports, no tone mapping is needed.

@GST-Main
Copy link

In addition, for HDR videos, if the maximum brightness used by the video source is lower than the maximum brightness of your monitor supports, no tone mapping is needed.

@CarterLi So, the tone mapping is for some videos with peak brightness that is brighter than device's max brightness spec, right?

@CarterLi
Copy link
Contributor

Yes.

@GST-Main
Copy link

First:

Start IINA and open the Video/Audio settings
Set Target peak to 50
Set Algorithm to clip
Restart IINA
Then:

Play The World in HDR in 4K (ULTRA HD)
Stop at around 00:18 when the two sliver jets are being shown
Notice how blown out and messed up the rear jet looks
Open the Video/Audio settings
Set Target peak to 0
Set Algorithm to auto
Restart IINA
Now:

Play The World in HDR in 4K (ULTRA HD)
Stop at around 00:18 again
Notice how much better looking the rear sliver jet is

I tested it and it works fine!

@tigerkzr
Copy link

Interesting aside. On my M2 MacBook Pro with v1.3.1, playing HDR video is very dark UNLESS I also play a video in VLC at the same time.

Also, I checked the latest 1.3.2 build and the dark screen HDR appears to be fixed.

@waydabber
Copy link

Yeah, it's super annoying indeed.

What you can do about the border is to use accessibility zoom and zoom the screen in to 105% for example. This way you can tune out the black borders (but of course your video won't be pixel perfect anymore if you care about that + some small content on the sides will be lost).

But I just mostly resorted to watching HDR videos in SDR mode or get my M1 MBP and use that for watching videos.

@waydabber
Copy link

btw - imho this issue should get a "bug" tag and a "priority: high" :)

@low-batt low-batt added the bug label Nov 14, 2023
@low-batt
Copy link
Contributor

This issue is not a priority for the development team because to investigate it requires a Mac with the M2 chip and probably an external monitor capable of HDR. Last I checked none of the developers possess the required equipment to look into this one.

The IINA code does not contain any checks that change the behavior when running on a M2 chip vs. running on a M1 chip. I don't know for sure, but I would be surprised if there is this level of conditionalization in the libraries that IINA uses. That suggests the difference in behavior between M1 working and M2 failing is coming from macOS. We've been hoping this problem would disappear in a macOS update. I used the word "suggests" because until an investigation identifies the root cause you can't say for sure where the fault lies.

I've not heard yet if this problem is still present under macOS Sonoma or what the situation is with the M3. I have upgraded one of my machines to macOS Sonoma 14.1.1. Shortly after the upgrade macOS crashed on me. I'm also encountering some new problems that do not reproduce on my primary development machine running macOS Ventura. I'm not recommending upgrading to Sonoma at this time.

@waydabber
Copy link

Yeah, Sonoma has a lot of issues (but this issue is present for Ventura as well). For M2 users who has a high refresh rate external display with HDR (or use a 4K TV at 120Hz), Sonoma 14.1 finally fixes the lack of HDR beyond certain resolutions (for example HDR at 2560x1440 120Hz was unavailable previously) that's been plaguing these systems for many months now. Strangely enough, on M1 Macs Sonoma 14.1 breaks HDR on exactly the same resolutions that were unavailable with M2 previous to 14.1 (probably somebody tried to fix this bug with M2 but obviously botched it). Apple is quite obviously struggling with this whole HDR thing (they probably don't really test their releases properly with third party displays, I suppose all developers use XDR displays which work completely differently thanks to the combined SDR-HDR mode with XDR EDR so they are blindsided).

Regarding the HDR bug, macOS properly reports the EDR range on M2 on third party HDR displays in HDR mode and generally HDR works just fine (tried it with some Metal layers + BetterDisplay has no problem with HDR brightness upscaling either, the EDR headroom is correctly reported and detected etc).

@low-batt
Copy link
Contributor

On HDR working fine and this:

tried it with some Metal layers

IINA is not using Metal; IINA is using OpenGL. As Apple has Deprecated OpenGL they may not be doing as much testing as they used to especially for HDR support.

For audio/video support IINA uses a library from the mpv project. The project has been working on a next generation renderer (GPU Next) that uses Vulkan instead of OpenGL. Recently support for using GPU Next under macOS was merged. This support relies upon MoltenVK to map Vulkan API calls to Metal. However IINA is unable to take advantage of GPU Next until support is added to libmpv. Last I heard they had run into some technical issues with that.

On this:

Strangely enough, on M1 Macs Sonoma 14.1 breaks HDR on exactly the same resolutions that were unavailable with M2 previous to 14.1

That is certainly interesting to hear. Seems to confirm the macOS needs chip specific graphics code as suspected. Pretty bad that Apple missed that the fix for M2 broke M1.

Had a friend who just got a MacBook Pro with the M3 Pro chip test streaming The World in HDR in 4K (ULTRA HD) using IINA 1.3.3. He reported HDR playback was fine in windowed and full screen modes. This was under macOS 14.1.1. Not clear yet if he will be able to test playback on an external HDR display.

@waydabber
Copy link

All right @low-batt - this makes sense, thanks. I plan to get an M3 MBP, will see if things work with an external HDR display. Can't test M2 with internal display myself for comparison as I only have a Studio from that generation (my MBP is still M1).

Note: an other trick with M2 to somewhat bring back HDR with IINA is to let it render darkly as it is but use BetterDisplay's HDR brightness upscaling feature (this is normally meant to help remap the normal SDR color range of the desktop to the HDR range, thus giving extra brightness both for third party HDR displays and Apple's XDR displays) but recalibrate it (using the calibration slider under Settings) to overcompensate for IINA's dim rendering. This is not a very nice solution, but kinda works (however due to the compressed dynamic range of the too dark rendering this deteriorates the quality somewhat and might result in some banding etc especially if the framebuffer depth is 8-bits instead of 10-bits).

@xanather
Copy link

Hi @waydabber, following up to your comment.

I have a 240hz HDR display with an M3 Macbook Pro Max running Sonoma. This problem still occurs.

IINA detects HDR fine when dragging the window onto the display but its just very dark.

The (Video->crop->custom->cancel) workaround fixes the issue, and the video becomes brighter than max SDR brightness so HDR definately kicks in.

IINA works fine on the in-built display, only related to external displays as far as I can tell.

@waydabber
Copy link

Thanks @xanather for the info!

Based on what @low-batt says, the problem is unlikely to be resolved as Apple indeed abandoned OpenGL and it's typical for things to start slowly breaking for deprecated stuff in macOS (well, sometimes even non-deprecated things start breaking slowly, I could name a few... 😄).

@caipod @low-batt - I think it might be a good idea to update the issue title to "Dark HDR video bug on M2/M3 chips" based on @xanather's report.

@xanather
Copy link

xanather commented Nov 16, 2023

IINA uses OpenGL? Apple M3 hardware is insane tech but their inability to support anything but the Metal API is really hindering them at this point. They added proper external monitor HDR support but there's not really any friendly codec universal video players that support playback in that mode without issues currently. Stupid.

@low-batt low-batt changed the title HDR bug on M2 chip. HDR bug on M2/M3 chip. Nov 16, 2023
@low-batt
Copy link
Contributor

On this:

I have a 240hz HDR display with an M3 Macbook Pro Max running Sonoma. This problem still occurs.

Darn. I was just about to report that my friend got back to me that HDR worked fine with his MacBook Pro with the M3 Pro chip running macOS 14.1.1 and using a LG TV model OLED65CXAUA through HDMI. This seems to indicate the problem involves some other factor that we have not yet identified.

One factor it would be nice to rule out is that the way the video is encoded has something to do with the problem. Did you test streaming The World in HDR in 4K (ULTRA HD)?

On this:

IINA uses OpenGL?

IINA has no choice but to use OpenGL until libmpv supports something else. On IINA's relationship to mpv

From the mpv player's site:

mpv is a free (as in freedom) media player for the command line.

For the Mac that means it is expected that you start mpv using Terminal. The site goes on to say:

On Screen Controller
While mpv strives for minimalism and provides no real GUI, it has a small controller on top of the video for basic control.

And most importantly from IINA's perspective:

Embeddable
A straightforward C API was designed from the ground up to make mpv usable as a library and facilitate easy integration into other applications.

As can be seen by looking over the OPTIONS section of the mpv manual, providing a full complete GUI for mpv is challenging due to the extensive ability to configure the player. If you add in the requirement that the GUI adhere to the conventions of the platform then that adds a considerable amount of work as mpv supports Linux, macOS, Windows and other platforms. As each of those platforms have their own GUI styles and conventions a lot of work is required to maintain GUIs that look "native" to each of those platforms. Publishing a library allows some other project to implement a native GUI.

Right at this moment the hold up is the following from the Known limitations / missing options section of the GPU Next vs GPU wiki post:

There is currently no support for the libmpv / render API in vo_gpu_next

Once that is solved then IINA will need to make the changes required to support the new renderer.

@xanather
Copy link

xanather commented Nov 17, 2023

Hey @low-batt, running that video via Safari the HDR works fine on both DP and HDMI as I would expect that it doesn't touch OpenGL. I could compare with Firefox which doesnt support HDR yet.

I have both HMDI and DisplayPort connections (I have quite a unique setup actually, three 240hz HDR 1440p displays all from one M3 chip, two DP and one HDMI). IINA darkness bug behaves the same on all three displays.

Unfortunately I don't have the time to contribute to mpv or IINA at the moment to help debug, but if anyone would like me to test any senarios with my setup fling me a message.

Can you share the video file your friend used that worked properly with IINA?

@low-batt
Copy link
Contributor

On this:

Can you share the video file your friend used that worked properly with IINA?

I had him stream the YouTube video: The World in HDR in 4K (ULTRA HD)

That Safari is working is more evidence that suggests this could be a problem with OpenGL.

@waydabber
Copy link

Now if I enable accessibility zoom and zoom the screen in even just 1% (or any negligible amount) the rendering appears to be correct both in windowed and full screen mode (without crop hack - running M2, Sonoma 14.2 beta3 with an external third party HDR display). As the app for sure does not do anything special during accessibility zoom, this finding clearly points to some kind of macOS desktop compositor issue to me.

Anyway, using accessibility zoom is the simplest, quickest and best workaround I found so far.

@low-batt
Copy link
Contributor

Thanks for posting that tip. I agree. This is more evidence that suggests the problem is in macOS.

@miku1958
Copy link

Another simple workaround is to mirror the external TV with the built-in screen

@kenyth
Copy link

kenyth commented Dec 30, 2023

I have the same exact issue on M2 MAX Mac Studio connecting to only one monitor.

For me, the proposed (Video->crop->custom->cancel) workaround works ONLY when NOT going fullscreen.

But before seeing this issue report, actually I found myself another workaround that works all the time, i.e., use the sidecar display feature to connect an iPad as an extended display. This sidecar connection workaround magically works all the time.

@waydabber
Copy link

An other workaround - if ScreenCaptureKit is used to capture the screen's contents, HDR rendering seems to be all right. You can use the ScreenCaptureKit tech demo or some other tool (there are many out there). Staring a Picture in Picture window for the display using BetterDisplay also works well (you can hide the window itself, it does not matter). i think this is a better solution than cropping or accessibility zoom hack as it's a few clicks and does not cause any distortions/loss of detail.

@xiushimt
Copy link

This sounds like a duplicate of issue #4214, except I have not heard anyone report this before:

but when I switch off the HDR, the player displays the right HDR effect.

Not sure what to make of that. If you enable HDR and then follow this workaround mentioned in issue #3906 does the dimming stop?:

Go to IINA menubar -> Video -> Crop -> Custom... -> Press the Cancel button in the right bottom corner

HDR was working fine on the M1 under macOS Monterey. The problem appeared on the M1 with the release of macOS Ventura. For this reason we have been assuming the problem is due to a defect in macOS. We were hoping 13.3 would have a fix for this, but the problem is still present.

In IINA 1.3.1 a horrible hackaround was added that so far as been effective in suppressing the dimming behavior on the M1.

The situation is different on the M2. On the M1 the problem only occurs in full screen mode. I'm hearing that is not true on the M2. So the problem is worse on the M2. It is very strange that the sequence shown above works to suppress the problem on the M2. As I do not have a Mac with the M2 chip I've not been able to look into what specifically it is about that sequence that causes the dimming to stop.

It's indeed a problem with macos
In macOS Sequoia Developer Beta2, the external monitor hdr is already displaying normally

@low-batt
Copy link
Contributor

@xiushimt Thank you for the update. Very helpful.

@waydabber
Copy link

Yes, I can confirm this, IINA was working fine both with Beta1 and Beta2 (the same config had issues under Sonoma). Tested with MBP M3 Max + external HDR display.

@low-batt
Copy link
Contributor

This is great news. I was concerned this was not fixed in Sonoma.

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

No branches or pull requests