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

Add Firefox 121+ to list of HEVC-supporting browsers #5876

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fanonwue
Copy link

@fanonwue fanonwue commented Aug 5, 2024

Mozilla implemented support for HEVC decoding using WMF on Windows. Support for HEVC playback is being tested anyway using the canPlayHevc() function, so this should be a safe change for other operating systems (or systems without hardware HEVC decoding) as well.

Changes
Firefox (121 and later) supports HEVC decode in fMP4 containers when it's using the new WMF-based media backend, so it should be added to the conditional check for that. The new backend is only available on Windows and not enabled by default (iirc), but when it's present, decoding works perfectly.
The canPlayHevc() function correctly reports decoding capabilities, so a fallback to H264 happens when media.wmf.hevc.enabled is disabled, WMF is not present or no hardware decoding is available (I was only able to test this using WSL2 so far, but I doubt that this is going to be different for "real" systems).

Issues
Fixes #5706

Mozilla implemented support for HEVC decoding using WMF on Windows. Support for HEVC playback is being tested anyway using the canPlayHevc() function, so this should be a safe change for other operating systems (or systems without hardware HEVC decoding) as well.

Fixes jellyfin#5706
@fanonwue fanonwue requested a review from a team as a code owner August 5, 2024 02:34
@gnattu
Copy link
Member

gnattu commented Aug 11, 2024

Firefox does not support 10bit HEVC and is lying with the feature tests. The playback will automatically fallback to transcoding with our fail and retry mechanism, but I think it is better to add check here:

// hevc main10 level 4.1
if (videoTestElement.canPlayType('video/mp4; codecs="hvc1.2.4.L123"').replace(/no/, '')
|| videoTestElement.canPlayType('video/mp4; codecs="hev1.2.4.L123"').replace(/no/, '')) {
maxHevcLevel = 123;
hevcProfiles = 'main|main 10';
}
// hevc main10 level 5.1
if (videoTestElement.canPlayType('video/mp4; codecs="hvc1.2.4.L153"').replace(/no/, '')
|| videoTestElement.canPlayType('video/mp4; codecs="hev1.2.4.L153"').replace(/no/, '')) {
maxHevcLevel = 153;
hevcProfiles = 'main|main 10';
}
// hevc main10 level 6.1
if (videoTestElement.canPlayType('video/mp4; codecs="hvc1.2.4.L183"').replace(/no/, '')
|| videoTestElement.canPlayType('video/mp4; codecs="hev1.2.4.L183"').replace(/no/, '')) {
maxHevcLevel = 183;
hevcProfiles = 'main|main 10';
}

Basically we should skip these main10 profile tests for Firefox so that they are not mistakenly marked as supported to avoid unnecessary retry and reduce video load time.

@fanonwue
Copy link
Author

fanonwue commented Aug 14, 2024

Nothing can ever be easy, huh?

So basically if the browser is Firefox, we should only add main and not main 10 to the profiles, right?

Copy link

sonarcloud bot commented Aug 14, 2024

@fanonwue
Copy link
Author

fanonwue commented Aug 14, 2024

I have added an override for Firefox's real capabilities at the end of the block of checks that determine HEVC profile compatibility (seems cleaner to me to do it at the end instead of making each condition longer, I doubt the "unnecessary" checks will make a significant difference).

// Firefox does not support 10-bit HEVC, but is lying about it's capabilities
if (browser.firefox) {
maxHevcLevel = 123;
hevcProfiles = 'main';
}

I was able to test this using a HEVC main and HEVC main10 video. The main10 one even gets transcoded into HEVC again (the setting for that is still on auto). Playback works perfectly, the main profile one is using direct play.

What @gnattu said confused me a bit tbh, because it was working before as well. But checking the logs showed that Jellyfin did an automatic fallback to transcoding when playback of the the main10 video failed. So I guess it's better to catch this beforehand.

This override will need to be removed once Firefox supports main10 playback though. Sad that they don't report the capabilities correctly.

@jellyfin-bot
Copy link
Collaborator

jellyfin-bot commented Aug 14, 2024

Cloudflare Pages deployment

Latest commit 7416f09
Status ✅ Deployed!
Preview URL https://3f282f4d.jellyfin-web.pages.dev
Type 🔀 Preview

View build logs

@fanonwue
Copy link
Author

Hi,

I understand that you are probably quite busy. But I wanted to ask whether anyone from the JF team thinks we can proceed with adding this? Is there something else I could do?

@gnattu
Copy link
Member

gnattu commented Aug 29, 2024

Please be patient as the web team is super busy. It is normal that a PR is not merged for weeks as lots of mine are in this state as well. I'm good with your current solution but we still need the web team members to look at it.

@kam821
Copy link

kam821 commented Sep 1, 2024

  1. It may be a good idea to further restrict HEVC to Windows only by adding appropriate check:
    (browser.firefox && browser.versionMajor >= 121 && browser.windows)
  2. Bugs I've noticed so far - on one HEVC-encoded video, a horizontal, green line is displayed at the bottom of the video content.
    So far, this problem only affects one video (series). Once, randomly I managed to play that title without that line appearing, but generally this line is almost always displayed.

Green line:
obraz

Encoding parameters of problematic video (container: mkv):
obraz

@gnattu
Copy link
Member

gnattu commented Sep 1, 2024

It may be a good idea to further restrict HEVC to Windows only by adding appropriate check:

Firefox on other platforms do not report HEVC as supported so this is currently redundant

Bugs I've noticed so far - on one HEVC-encoded video, a horizontal, green line is displayed at the bottom of the video content.

We can do little if it is a firefox bug

@kam821
Copy link

kam821 commented Sep 2, 2024

We can do little if it is a firefox bug

This may not necessarily be a problem with Firefox itself.
I found some links that describe same/similar problem that has been fixed in the past.
jellyfin/jellyfin#2292
jellyfin/jellyfin#3021
jellyfin/jellyfin#5535

@nyanmisaka
Copy link
Member

We can do little if it is a firefox bug

This may not necessarily be a problem with Firefox itself. I found some links that describe same/similar problem that has been fixed in the past. jellyfin/jellyfin#2292 jellyfin/jellyfin#3021 jellyfin/jellyfin#5535

One is an AMD driver issue and the other two are a QSV filter issue I handled in the past. They are not related to this one because there is no hardware transcoding involved. If Chrome doesn't have this problem on the same file, then you need to wait for Firefox to fix their frame cropping.

@GodTamIt
Copy link
Contributor

Firefox does not support 10bit HEVC and is lying with the feature tests.

@gnattu Which feature tests/under which conditions is Firefox lying? I recently filed a related bug and may look into upstreaming a fix for it so might be useful to collect all issues into a fix.

This link might be helpful: https://cconcolato.github.io/media-mime-support

@gnattu
Copy link
Member

gnattu commented Sep 22, 2024

Which feature tests/under which conditions is Firefox lying?

Firefox reports HEVC main10 as supported for canPlayType() method but it actually does not, see code quoted here for the real test.

@nyanmisaka
Copy link
Member

@fanonwue Just tested Firefox 132 stable with media.wmf.hevc.enabled == 1 and found that HEVC Main 10 playback has been fixed in this version. Client-side HDR tonemapping is still not supported. But I think this PR can go ahead.

firefox132

@fanonwue
Copy link
Author

@fanonwue Just tested Firefox 132 stable with media.wmf.hevc.enabled == 1 and found that HEVC Main 10 playback has been fixed in this version. Client-side HDR tonemapping is still not supported. But I think this PR can go ahead.

firefox132

In that case, do you want me to adjust the workaround to only work below 132?

@nyanmisaka
Copy link
Member

In that case, do you want me to adjust the workaround to only work below 132?

Since HEVC is experimental in older versions, I don't think it's necessary to add a workaround specifically for those broken versions, as browser updates are usually frequent.

@fanonwue
Copy link
Author

In that case, do you want me to adjust the workaround to only work below 132?

Since HEVC is experimental in older versions, I don't think it's necessary to add a workaround specifically for those broken versions, as browser updates are usually frequent.

Sorry, this is my first time contributing to a larger project: Do you want me to revert the last commit that introduced the override then? I think it would be good to update the minimum FF version to 132 then as well, I've set it to 121 in the original commit.

@nyanmisaka
Copy link
Member

Sorry, this is my first time contributing to a larger project: Do you want me to revert the last commit that introduced the override then? I think it would be good to update the minimum FF version to 132 then as well, I've set it to 121 in the original commit.

It should be enough to bump the checked version up to 132.
All that's left is for the user to manually enable the experimental flag in Firefox.

HEVC 10bit was broken before, but the support seems to be mores table now
Copy link

sonarcloud bot commented Oct 31, 2024

@fanonwue
Copy link
Author

It should be enough to bump the checked version up to 132.

I've removed the previous override (disallowing HEVC main10) and raised the minimum version to 132.

@gnattu
Copy link
Member

gnattu commented Oct 31, 2024

We have more problems regarding this because Firefox 132 on Windows is lying again where it will report HEVC as supported even that flag is disabled as long as the media codec extension is installed which is super annoying. In the worst case we have to implement manual switch for Firefox users to enable this manually but I really don't want to go that approach.

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.

HEVC support for Firefox 120/121+ (Windows)
6 participants