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

Videos: Improve detection of HEVC support for Google Chrome #3275

Closed
lks-nbg opened this issue Mar 12, 2023 · 9 comments
Closed

Videos: Improve detection of HEVC support for Google Chrome #3275

lks-nbg opened this issue Mar 12, 2023 · 9 comments
Assignees
Labels
idea Feedback wanted / feature request released Available in the stable release video Video Formats, Transcoding, FFmpeg, Streaming & Co

Comments

@lks-nbg
Copy link

lks-nbg commented Mar 12, 2023

Describe what problem this solves and why this would be valuable to many users

Last year Google added native support for HEVC/H.265 videos to Chrome 107 (https://chromestatus.com/feature/5186511939567616). Therefore transcoding is not necessary and can be skipped (like in #2379 for Safari) which improves playback performance and the amount of work done by the server.

Describe the solution you'd like

I used "User-Agent Switcher for Chrome" to test the functionality. By spoofing Safari as user-agent in Chrome, the playback performance improved significantly. So I assume the only changes required to implement this, are to adapt PR #2379 and skip transcoding for Chrome.

Describe alternatives you've considered

Additional context

List of supported browsers / version: https://caniuse.com/hevc

@lks-nbg lks-nbg added the idea Feedback wanted / feature request label Mar 12, 2023
@LeehamElectronics
Copy link

I thought transcoding was not done 'on the fly.' From what I can tell, videos are transcoded to AVC when they are played for the first time or when running the command.

@lastzero
Copy link
Member

@lks-nbg It's interesting that it depends on the "User Agent Switcher" for you, as this frontend code should dynamically detect HEVC support:

export const canUseHevc = canUseVideo
? !!document.createElement("video").canPlayType('video/mp4; codecs="hvc1"')
: false;

I also can't find the code you referenced in the photo model anymore?

@lastzero
Copy link
Member

Did you check if the transcoding was caused by the bitrate limitation or if maybe the AVC version was streamed after all and the transcoding was simply not needed the second time (since it was cached)?

@lastzero lastzero added the video Video Formats, Transcoding, FFmpeg, Streaming & Co label Mar 15, 2023
@lks-nbg
Copy link
Author

lks-nbg commented Mar 16, 2023

@lastzero: you are right. I tested several videos but apparently they were all cached... Embarrassing, sorry about that.

I checked with the media tab in chrome inspector and in both cases h.264 is used, even though chrome should support h.265. According to this blog the issue is within the canPlayType method. Chromium does not accept incomplete/ambiguous codec ids for HEVC (like 'hvc1'). The Codec string must have info about codec level/profile, as described in ISO/IEC FDIS 14496-15 section E.3, for example "hev1.1.6.L93.B0" (source)

Therefore the current "canUseHevc" code will always return false on Chromium based browsers.

export const canUseHevc = canUseVideo
  ? !!document.createElement("video").canPlayType('video/mp4; codecs="hvc1"')
  : false;

The solution mentioned in the blog was to specify the codec in the canUseHevc method to something like 'hvc1.2.4.L153.B0'.
Is this a viable approach for photoprism to add HEVC support for Chromium based browsers?

lastzero added a commit that referenced this issue Apr 14, 2023
Signed-off-by: Michael Mayer <michael@photoprism.app>
@lastzero lastzero self-assigned this Apr 14, 2023
@lastzero lastzero added the please-test Ready for acceptance test label Apr 14, 2023
@lastzero
Copy link
Member

I have changed the detection as suggested. An updated preview build will be available soon. As always, any help with testing is much appreciated!

@lastzero lastzero changed the title Videos: Skip transcoding of HEVC / H.265 for Chrome Videos: Improve detection of HEVC support for Google Chrome Apr 14, 2023
@balajisraghavan
Copy link

I'm having the same issue - HEVC videos play in Chrome but not within PhotoPrism UI. Would be happy to help test the change. How do I pull a preview build and test? I run as a docker container in Linux

@lastzero
Copy link
Member

@lastzero
Copy link
Member

You can also test on our demo, by the way. It's based on the preview build.

@balajisraghavan
Copy link

Confirmed the fix works, thanks @lastzero. I see the new check in browser dev tools -canPlayType('video/mp4; codecs="hvc1.1.6.L93.90"');

Chrome plays HEVC files now. Server log shows video: '....mp4' is HVC1 compressed and requires no transcoding, average bitrate 40.3 MBit/s

@lastzero lastzero added tested Changes have been tested successfully and removed please-test Ready for acceptance test labels Apr 14, 2023
@graciousgrey graciousgrey added released Available in the stable release and removed tested Changes have been tested successfully labels May 3, 2023
@lastzero lastzero moved this to Released 🌈 in Roadmap 🚀✨ Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Feedback wanted / feature request released Available in the stable release video Video Formats, Transcoding, FFmpeg, Streaming & Co
Projects
Status: Release 🌈
Development

No branches or pull requests

5 participants