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

Can audio support MP3 encoding? AAC requires a commercial license #29

Closed mtsee closed 7 months ago

mtsee commented 9 months ago

Currently only aac and opus are supported, but opus synthetic mp4 cannot play normally.

Vanilagy commented 9 months ago

From https://www.via-la.com/licensing-2/aac/aac-faqs/:

Are there use fees for AAC? No. License fees are due on the sale of encoders and/or decoders only. There are no patent license fees due for the distribution of bit-streams encoded in AAC, whether such bit-streams are broadcast, streamed over a network, or provided on physical media.

This is in line with what WIkipedia states:

No licenses or payments are required for a user to stream or distribute content in AAC format.

So you should be totally fine using AAC for anything you want, unless it's selling an encoder/decoder. That said, adding MP3 codec support to this library does seem reasonable - I'll look into it.

Vanilagy commented 9 months ago

Are you even able to produce an AudioEncoder using MP3? I'm in Chrome 120, and according to this, I tried out several configurations:

audioEncoder.configure({
    codec: 'mp3', // or 'mp4a.69', or 'mp4a.6B'
    sampleRate,
    numberOfChannels,
    bitrate: 128000,
});

I always get DOMException: Unsupported codec type.. No reason to add MP3 support to the muxer if browsers can't even encode it.

mtsee commented 9 months ago

I made a video editing tool in the browser, which is charged according to the AAC protocol, so I use MP3 encoding for the audio. The current solution is to use ffmpeg.wasm to synthesize the video and mp3. If mp4-muxer supports MP3 encoding, you can remove ffmpeg.wasm, or does the author have any good suggestions? I can try to implement the encoding business of mp3, thanks

Vanilagy commented 9 months ago

I don't mind adding MP3 support to mp4-muxer, but if AudioEncoder can't even do it, there's little point. Keep me updated if you can manage the encoding business.

Vanilagy commented 7 months ago

I'll close this issue for now as it seems stale. If you still need help with something, feel free to reopen it :)

xeoshow commented 6 months ago

It seems we can decode mp3/ogg via Web Audio API .decodeAudioData(), but just can not encode to mp3/ogg via Web Audio API? Thanks.

Vanilagy commented 6 months ago

Yup, basically.

weepy commented 5 months ago

for anyone that's interested - I found this => https://github.com/salomvary/fdk-aac.js/blob/master/aac-enc.wasm - it seems to work well in my tests. Basically it will encode AAC from a wav file using wasm.

Vanilagy commented 5 months ago

@weepy No need to use WASM for this anymore now with WebCodecs! Simply decode the WAV data using decodeAudioData, then pipe it into an AudioDecoder. AAC is not an issue, just MP3 doesn't work.