jellyfin / jellyfin-web

Web Client for Jellyfin
https://jellyfin.org
GNU General Public License v2.0
2.28k stars 1.22k forks source link

HDR Transcoding in Edge Even Though I Have HDR #4899

Closed SmoochySix4 closed 8 months ago

SmoochySix4 commented 11 months ago

Describe The Bug The HDR HEVC movie keeps getting transcoded to non-HDR H264 even though my monitor is HDR, the setting is on in Windows 11, and it works fine in Plex, YouTube, Amazon, Max, etc...

All required browser extensions/codecs from the Microsoft App Store are downloaded.

Media Information

Input #0, matroska,webm, from '/tank/Movies/Dune (2021) [tmdbid-438631]/Dune (2021) [tmdbid-438631].mkv':
  Metadata:
    encoder         : libebml v1.4.4 + libmatroska v1.7.1
    creation_time   : 2023-02-08T02:32:28.000000Z
  Duration: 02:35:24.99, start: 0.000000, bitrate: 7257 kb/s
  Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn (default)
    Metadata:
      BPS             : 6486574
      DURATION        : 02:35:24.983000000
      NUMBER_OF_FRAMES: 223576
      NUMBER_OF_BYTES : 7560899441
      _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2023-02-08 02:32:28
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(eng): Audio: eac3, 48000 Hz, 5.1(side), fltp, 768 kb/s (default)
    Metadata:
      BPS             : 768000
      DURATION        : 02:35:24.992000000
      NUMBER_OF_FRAMES: 291406
      NUMBER_OF_BYTES : 895199232
      _STATISTICS_WRITING_APP: mkvmerge v73.0.0 ('25 or 6 to 4') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2023-02-08 02:32:28
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:2: Video: png, rgb24(pc), 1280x720 [SAR 3780:3780 DAR 16:9], 90k tbr, 90k tbn (attached pic)
    Metadata:
      filename        : cover.png
      mimetype        : image/png

Screenshots

Screenshot 2023-10-20 205748

Screenshot 2023-10-20 210959

System (please complete the following information):

Additional Context

dmitrylyzo commented 10 months ago

In 10.8, HDR10 isn't specified for HEVC: https://github.com/jellyfin/jellyfin-web/blob/d274d7f74187e2f5fe601e022183ddaa68281c8e/src/scripts/browserDeviceProfile.js#L841-L844

In 10.9, it is enabled for HEVC, but disabled for Edge :man_shrugging: : https://github.com/jellyfin/jellyfin-web/blob/5e8cc3f9150987846c8458cbe1e33f9689b1ba51/src/scripts/browserDeviceProfile.js#L196-L198

nyanmisaka commented 10 months ago

Edge does not support tone-mapping when there is no GPU, and when there is a GPU, the tone-mapped SDR color is a mess. As for the case where the display HDR has been manually turned on, we need a check to bypass this.

@dmitrylyzo Do you know how to check if the current display is SDR or HDR in a browser?

And it has recently introduced more bugs to the point where it cannot decode AV1. But it still reports via canPlaytype that it supports AV1.

dmitrylyzo commented 10 months ago

@dmitrylyzo Do you know how to check if the current display is SDR or HDR in a browser?

Maybe https://stackoverflow.com/a/75213217 (for modern browsers), but I haven't tested.

We could add a checkbox to toggle HDR support (I had this idea when I was trying to implement the IsHDR param - it is replaced by your VideoRange). Not all HDR capable panels have sufficient brightness/contrast - scenes become too dark. With this checkbox, we can disable HDR to force tone-mapping.

SmoochySix4 commented 10 months ago

I am not sure I understand where the issues lie, then, as I have had no issues with the color on Amazon, Plex, or Netflix when using Edge Chromium with HEVC HDR10.

What should be the selection is, if you have tone mapping turned off in the settings, then jellyfin-web should ignore anything related to the video having HDR and just direct stream the video, instead of forcing the transcode. If tone mapping is turned off, what is the point of the transcode to begin with?

That being said, if I were to want to enable Edge Chromium as an HDR supported browser in jellyfin-web, what & where would I make the modification?

dmitrylyzo commented 10 months ago

I am not sure I understand where the issues lie, then, as I have had no issues with the color on Amazon, Plex, or Netflix when using Edge Chromium with HEVC HDR10.

Since your display supports HDR, tone mapping is not required. But it may be dark if the brightness is insufficient (nits?). In your case, enabling HDR will work. That's why Nyan asked how to detect HDR capability from JS.

What should be the selection is, if you have tone mapping turned off in the settings, then jellyfin-web should ignore anything related to the video having HDR and just direct stream the video, instead of forcing the transcode. If tone mapping is turned off, what is the point of the transcode to begin with?

Having client-side Enable tone-mapping is also useful. But we still need to know if the client supports HDR10 or DolbyVision - this can trigger transcoding (can HDR10, but can't DoVi). So mentioned checkbox was intended as a device profile setting.

That being said, if I were to want to enable Edge Chromium as an HDR supported browser in jellyfin-web, what & where would I make the modification?

As a workaround, change this block to:

        if (browser.edgeChromium || browser.chrome || browser.firefox) {
            hevcVideoRangeTypes += '|HDR10|HLG';    // add this
            vp9VideoRangeTypes += '|HDR10|HLG';
            av1VideoRangeTypes += '|HDR10|HLG';
        }
nyanmisaka commented 10 months ago

Maybe https://stackoverflow.com/a/75213217 (for modern browsers), but I haven't tested.

Great. Maybe YouTube is using this API, so it can provides HDR video options dynamically.

We could add a checkbox to toggle HDR support (I had this idea when I was trying to implement the IsHDR param - it is replaced by your VideoRange). Not all HDR capable panels have sufficient brightness/contrast - scenes become too dark. With this checkbox, we can disable HDR to force tone-mapping.

Make sense.

nyanmisaka commented 10 months ago

For the record, DoVi P5 on Windows Chrome/Edge requires this option. But it's disabled by default.

chrome://flags/#enable-media-foundation-clear

image

SmoochySix4 commented 10 months ago

I downloaded the source code, modified the .js file, and currently testing with npm start, but that file is still being transcoded. Still saying the videos range is not supported. Do I need to disable tone mapping as well?

dmitrylyzo commented 10 months ago

I downloaded the source code, modified the .js file, and currently testing with npm start, but that file is still being transcoded. Still saying the videos range is not supported. Do I need to disable tone mapping as well?

Just in case, are you connecting http://localhost:8081?

Check the payload for PlaybackInfo in the Developer Tools / Network. There should be

"CodecProfiles": [{
    "Codec": "hevc",
    "Conditions": [{
        "Condition": "EqualsAny",
        "IsRequired": false,
        "Property": "VideoRangeType",
        "Value": "SDR|HDR10|HLG"    // <-- here supported video ranges
    }]
}]
SmoochySix4 commented 10 months ago

Okay, I am not sure where that is. First timer with nodejs and the like. But... I did figure out what was wrong on my end. I had checked out 10.8.9, and it didn't work. Works great on 10.8.11. No transcoding at all.

Now, to figure out how to stop it from letterboxing a 1080p video on a 2k monitor...

Thanks for all of the help.

dmitrylyzo commented 10 months ago

Works great on 10.8.11. No transcoding at all.

With this workaround? Or just clean 10.8.11? Or disabled video transcoding?

SmoochySix4 commented 10 months ago

Sorry. Yeah, 10.8.11 with the edit to the browserDeviceProfile.js

msimic commented 10 months ago

Edge does not support tone-mapping when there is no GPU, and when there is a GPU, the tone-mapped SDR color is a mess. As for the case where the display HDR has been manually turned on, we need a check to bypass this.

@dmitrylyzo Do you know how to check if the current display is SDR or HDR in a browser?

And it has recently introduced more bugs to the point where it cannot decode AV1. But it still reports via canPlaytype that it supports AV1.

if (screen.colorDepth > 24 && window.matchMedia('(color-gamut: p3)').matches) { 
  /* use HDR content, or if you want you can check also for rec2020 */ 
} else { 
  /* use SDR content */ 
}

But can you elaborate on the no-GPU thing? How can you run Edge without a gpu? It is not a terminal application that you can view over SSH :D

nyanmisaka commented 10 months ago

I think most people can infer from the context that no GPU means the GPU hardware acceleration is disabled in Chrome (artificial/driver bug list/driver not installed).

Avamander commented 9 months ago

I have a similar experience, basically everything HEVC (up to 8K@60, 10bit, PQ/HLG), VP9, AV1 decodes fine but Jellyfin Web tends to start transcoding quite often. Basically everything except Dolby Vision P5 and Rext plays correctly, which this test page confirms. (The MediaFoundation flag suggested above changed nothing, Edge just doesn't seem to handle the DV P5 color space correctly)

If at all possible a checkbox to fall back to transcoding in those few rare cases would be significantly nicer.