CarterLi / iina

The modern video player for macOS with additional features and bug fixes.
https://iina.io
GNU General Public License v3.0
681 stars 29 forks source link

Disable HDR for SDR videos #48

Closed sclsj closed 2 years ago

sclsj commented 2 years ago

System and IINA version:

Expected behavior: For non-HDR videos, no HDR-related things/functions (don't really know how to call them) is used. Therefore, you can avoid Apple's buggy implementation of HDR.

Actual behavior: All video and audio opened, no matter the HDR status, makes IINA call HDR things/functions which trigger Apple's bug.

Details For whatever reason, using HDR-related things/functions on macOS (XDR displays) result in fluctuation in brightness and 100% (really 100 x CPU cores %) windowserver CPU usage. This is not a bug in IINA. However, you can avoid this bug by not using HDR, like the system player and the original IINA player, when playing non-HDR content. If a video demonstrating this would be helpful, let me know where I can upload it.

How often does this happen? Everyone a file is opened by IINA when no un-hidden (foreground or background) windows are present.

CarterLi commented 2 years ago

We don't enable HDR mode with SDR content. How can I reproduce it?

sclsj commented 2 years ago

Just open a SDR video in IINA plus, I guess? I'm uploading a demo to OneDrive now.

CarterLi commented 2 years ago

Just open a SDR video in IINA plus, I guess? I'm uploading a demo to OneDrive now.

I did that a lot of times, and got no issues.

sclsj commented 2 years ago

Hopefully you can see the fluctuation in brightness. Still uploading now.

sclsj commented 2 years ago

https://scls-my.sharepoint.cn/personal/joyjin_scls-sh_org/_layouts/15/guestaccess.aspx?docid=0dccc7fefd55545eb8c558e62a6a60699&authkey=AcxWBzwNZwHeQKUNDT0x1ko&e=iOJgFn

sclsj commented 2 years ago

I also tried setting max SDR brightness to 1000 nits with Lunar and have similar issues when transitioning, so I don't think it's an IINA bug. Here's a demo. The brightness fluctuation is more apparent with this.

sclsj commented 2 years ago

Which MBP model are you using and what macOS version are you on? I felt like this might be due to different system configurations but I'm not sure. Maybe if I do a system restore with Apple Configurator like some people have done this problem will disappear? Unfortunately I don't really have the time to migrate all the data I already have.

CarterLi commented 2 years ago

My network is not very good and I dont want to download 708MB to test a small issue. Please cut your video into smaller one ( several seconds are enough ). Also please test it with the official IINA version to see if this issue only happens on IINA-plus.

sclsj commented 2 years ago

It does not happen with the official IINA version, as I've stated in the bug description. Please tell me an acceptable size for you and I will work to meet the limit.

CarterLi commented 2 years ago

Please cut it ( but do NOT convert it ) into about 10 seconds

https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg

sclsj commented 2 years ago

https://user-images.githubusercontent.com/38654636/165521501-0964ef8c-606b-4579-81b9-466a7aad9eaf.mp4

Sorry, I missed you comment. I cut using quicklook and compressed using handbrake (CQ 25). I hope the quality is still fine for you. At least I can't tell any differences.

CarterLi commented 2 years ago

Maybe video source specific. Please cut the Stress.mp4 and upload it.

打开你上传的这个IINA.Plus+Original.IINA.mp4文件屏幕会闪吗?

sclsj commented 2 years ago

打开你上传的这个IINA.Plus+Original.IINA.mp4文件屏幕会闪吗?

用IINA-Plus会,其他,如VLC,quicklook, QuickTIme, IINA不会

sclsj commented 2 years ago

Maybe video source specific. Please cut the Stress.mp4 and upload it.

I actually tested with an audio later on in the recording but forgets about it and cut it out. Let me upload that part again.

CarterLi commented 2 years ago

打开你上传的这个IINA.Plus+Original.IINA.mp4文件屏幕会闪吗?

用IINA-Plus会,其他,如VLC,quicklook, QuickTIme, IINA不会

That's strange. Since this repo has existed for several months, if it was a common issue, someone else should have encountered it.

sclsj commented 2 years ago

https://user-images.githubusercontent.com/38654636/165525991-d8c5791e-6366-46ca-8003-cf6ee1bc58f5.mp4

This is testing with opening audio. It is less obvious but I think you can still see some brightness fluctuation.

CarterLi commented 2 years ago

Completely no. I'm sorry.

sclsj commented 2 years ago

That's strange. Since this repo has existed for several months, if it was a common issue, someone else should have encountered it.

It is quite strange. There are other weird graphic glitches like non-existent window (i.e. should be in another location) being rendered on screen. I'm not sure whether it's because something wrong with the software or the hardware. I've heard online that some people have some issues with their m1 macs until they erased and reinstalled macOS. Maybe that's what's happening.

Until anyone else can confirm the behavior on their laptop I guess this is just an isolated case.

sclsj commented 2 years ago

Completely no. I'm sorry.

I understand. The fluctuation is quite subtle on camera and is easily interpreted as other unrelated phenomenons such as auto exposure change. Can you see the brightness fluctuation on the first video though?

CarterLi commented 2 years ago

Completely no. I'm sorry.

I understand. The fluctuation is quite subtle on camera and is easily interpreted as other unrelated phenomenons such as auto exposure change. Can you see the brightness fluctuation on the first video though?

Yes, I can. However it didn't happen for me. So I requested you uploading the cuttedStress.mp4 file

sclsj commented 2 years ago

Here are some console logs: IINA-plus

默认  21:37:37.917474+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 1.02529, ambient: 5.47863, filtered ambient: 17.2116, limit: 400
默认  21:37:37.985379+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 1.07381, ambient: 5.47863, filtered ambient: 17.2116, limit: 400
默认  21:37:38.082391+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 1.26232, ambient: 5.47863, filtered ambient: 17.2116, limit: 400
默认  21:37:38.122862+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 1.33734, ambient: 5.47863, filtered ambient: 17.2116, limit: 400
默认  21:37:39.244524+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 5.86721, ambient: 5.47863, filtered ambient: 17.2116, limit: 1153.26
默认  21:37:39.528525+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 8.01516, ambient: 5.47863, filtered ambient: 17.2116, limit: 1575.47
默认  21:37:39.689451+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 8.13997, ambient: 5.47863, filtered ambient: 17.2116, limit: 1600
默认  21:37:40.005932+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 8.13997, ambient: 5.47863, filtered ambient: 17.2116, limit: 1600
默认  21:37:48.081635+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 8.05474, ambient: 5.31468, filtered ambient: 16.6966, limit: 1583.25
默认  21:37:48.220196+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 6.94304, ambient: 5.31468, filtered ambient: 16.6966, limit: 1364.73
默认  21:37:48.402401+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 5.72897, ambient: 5.31468, filtered ambient: 16.6966, limit: 1126.09
默认  21:37:48.481518+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 5.20403, ambient: 5.31468, filtered ambient: 16.6966, limit: 1022.91
默认  21:37:48.927524+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 3.83303, ambient: 5.31468, filtered ambient: 16.6966, limit: 753.424
默认  21:37:49.015824+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 2.97516, ambient: 5.31468, filtered ambient: 16.6966, limit: 584.8
默认  21:37:49.081327+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 2.79866, ambient: 5.31468, filtered ambient: 16.6966, limit: 550.107
默认  21:37:49.238864+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 2.56453, ambient: 5.31468, filtered ambient: 16.6966, limit: 504.087
默认  21:37:49.498092+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 1.79244, ambient: 5.31468, filtered ambient: 16.6966, limit: 400
默认  21:37:49.770308+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 1.55861, ambient: 5.31468, filtered ambient: 16.6966, limit: 400
默认  21:37:49.983711+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: 1.08937, ambient: 5.31468, filtered ambient: 16.6966, limit: 400
默认  21:37:58.964790+0800    WindowServer    Display 1 commitBrightness sdr: 151.201, headroom: -1, ambient: 5.38952, filtered ambient: 16.9317, limit: -1

IINA

nothing when searching "sdr"

This is when opening the "stress.mp4" file.

sclsj commented 2 years ago

I will upload a sample soon.

Completely no. I'm sorry.

I understand. The fluctuation is quite subtle on camera and is easily interpreted as other unrelated phenomenons such as auto exposure change. Can you see the brightness fluctuation on the first video though?

Yes, I can. However it didn't happen for me. So I requested you uploading the cuttedStress.mp4 file

sclsj commented 2 years ago

https://user-images.githubusercontent.com/38654636/165532725-c490e261-45ec-4977-9cff-509bfeb92fb4.mp4

sclsj commented 2 years ago

As I've said, this happens with literally every video and audio, so here is a demo with the IINA-Plus.Audio.mp4 I just sent you.

https://user-images.githubusercontent.com/38654636/165533621-736994ea-9c4e-4906-b8bd-709af04f1c7c.mp4

CarterLi commented 2 years ago

No...

https://user-images.githubusercontent.com/6134068/165534927-4a11e9e3-968a-45b0-900f-d2a856fac40c.mov

sclsj commented 2 years ago

Actually, I forget to say this: this brightness fluctuation is not present in the screen recording. So I choose to film it with my iPhone instead of recording the screen. This is the reason why I think it has something to do with how Apple scales brightness with SDR/HDR videos.

sclsj commented 2 years ago

And did you try to search for "sdr" in Console? Did you get the same behavior as the one I posted?

sclsj commented 2 years ago

Regardless of whether the brightness fluctuation is present, if there is relevant logs in Console then IINA-plus is using HDR somehow.

CarterLi commented 2 years ago

SDR is bt.709

$ mediainfo /Users/carter/Desktop/stress.mp4
...
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Codec configuration box                  : avcC
...

All HDR related logics will be bypassed when we detect bt.709

https://github.com/iina-plus/iina/blob/develop/iina/VideoView.swift#L348

CarterLi commented 2 years ago

We don't print logs with SDR content, as it's the general path.

sclsj commented 2 years ago

We don't print logs with SDR content, as it's the general path.

Could you please explain what do you mean by that? The logs are from WindowServer which scales brightness for SDR/HDR content. See https://alinpanaitiu.com/blog/over-500nits-failed/ for where I get the keyword.

sclsj commented 2 years ago

Sorry, I don't know any programming language☹️. Here are my observations:

Based on these three observations, there seems to be a correlation between HDR mode, screen brightness range / limit messages in Console, and screen brightness fluctuations. Therefore, my educated guess is that IINA (plus) is using HDR mode when playing SDR videos.

Please tell me if I'm wrong in any of these reasoning steps.

CarterLi commented 2 years ago

I think I find something, please wait a minute

CarterLi commented 2 years ago

New binaries generated. Please have a test.

sclsj commented 2 years ago

The new binaries no longer triggered this bug.

CarterLi commented 2 years ago

Thanks for reporting