Vanilagy / mp4-muxer

MP4 multiplexer in pure TypeScript with support for WebCodecs API, video & audio.
https://vanilagy.github.io/mp4-muxer/demo
MIT License
419 stars 32 forks source link

HEVC support for encoding #58

Closed BryanChrisBrown closed 3 months ago

BryanChrisBrown commented 3 months ago

This library is so cool, thanks so much for making it!

I'm trying to figure out how to use HEVC encoding, but can't seem to find any valid encoders, more of a question than an issue, but is there a web codecs call to check available encoders? or a list somewhere? I tried reading through the web codecs spec but only find the hvc1 flag, not the special magic string beyond :(

Vanilagy commented 3 months ago

Thank you!

I'll take you down the path of how I would typically find out this stuff:

All of the codecs available in the Web Codecs API have a "registration" page you can find on google. Here's the one for HEVC: CleanShot 2024-07-19 at 21 48 53@2x https://www.w3.org/TR/webcodecs-hevc-codec-registration/

In §1, it specifies the codec string to be:

The codec string begins with the prefix "hev1." or "hvc1.", with a suffix of four dot-separated fields as described in Section E.3 of [iso14496-15].

This is where it starts leading you down the spec rabbit hole, that's how it goes with these media codecs. These spec documents typically cost around 200 CHF (Swiss Franks) to get them "the correct way", but you can typically find PDFs lying around on Google pretty easily. Here's one.

When you look at section E.3, you see the formal definition of the codec string and the meaning of all the parts: CleanShot 2024-07-19 at 21 52 18@2x

That definition leads you even further into the spec, as you'll have to find out what all of the referenced variables are. However, the example also provides the example string hev1.1.6.L93.B0. Maybe you can try that one!


There's also this library here: https://github.com/dmnsgn/media-codecs

I'd recommend trying it! It produces these codec strings for you from simple, human-readable input.

BryanChrisBrown commented 3 months ago

Thank you so much, these are some great resources!

The medic codecs library from dmnsgn looks great from the readme, but crashes for me when I try to load the page (windows + nvidia graphics) , does it do the same for you?

BryanChrisBrown commented 3 months ago

ah it just took it a while, looks like no HEVC codecs are supported on my system for encoding :'(

Vanilagy commented 3 months ago

That's a shame. Perhaps it'll change in the future!

BryanChrisBrown commented 2 months ago

Turns out if you run chrome/edge/chromium based browsers above v107 and use this flag when running them --enable-features=PlatformHEVCEncoderSupport HEVC support will work.

I haven't been able to get it above 1920 x 1080p though :/

I can exceed 1080p when using AVC, but for some reason when I try to increase the resolution beyond that, then I get the failed decoder message.

Vanilagy commented 2 months ago

Well, I assume the max resolution depends on the codec string you pass! If you increase the "level" more, you should be able to achieve higher resolutions. AVC has the same thing, if you set the level too low (specified in the codec string), you can't exceed a certain resolution.

BryanChrisBrown commented 2 months ago

on windows, it's hardcoded to 1920 x 1080p, if you build chrome from source you can bypass that,

https://issues.chromium.org/issues/40233328

Vanilagy commented 2 months ago

Super random