w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.
https://w3c.github.io/webcodecs/
Other
977 stars 136 forks source link

How to encode aac-lc in webcodecs #259

Closed runner365 closed 2 years ago

runner365 commented 3 years ago

Hi, I try to encode aac-lc in webcodecs: try in the way:

this.aencoder_.configure({ codec: 'aac', numberOfChannels: 2, sampleRate: 44100 });

try in the way:

this.aencoder_.configure({ codec: 'mp4a.40.02', numberOfChannels: 2, sampleRate: 44100 });

try in the way:

this.aencoder_.configure({ codec: 'mp4a.40.2', numberOfChannels: 2, sampleRate: 44100 });

try in the way:

this.aencoder_.configure({ codec: 'mp4a.40.17', numberOfChannels: 2, sampleRate: 44100 });

but They turns out: "unsupported codec type".

I read reference from:

But I fail to get the answers, Please help.

chcunningham commented 3 years ago

I think your the mp4a* strings are all correct, but you're getting "unsupported" simply because we (Chrome) haven't implemented aac encoding yet. Currently the only supported audio encoder is opus. AAC encode support is on our roadmap, but it may not be included at initial launch.

tlecoz commented 2 years ago

@chcunningham almost one year later, what about AAC ? Is it usable now ?

This page make me think it's doable https://www.w3.org/TR/webcodecs-aac-codec-registration/

but when I try to do this

this.audioEncoder.configure({
            codec:"mp4a.40.2",
            //codec: "opus",
            sampleRate:samplerate,
            numberOfChannels:channelCount,
            bitrate:bitrate,
            aac:{format:"aac"} 
        });

I get the error : DOMException: Failed to execute 'configure' on 'AudioEncoder': Unsupported codec type.

Any help is welcomed !

sandersdan commented 2 years ago

AAC encoding in Chrome's WebCodecs implementation is experimental, and in particular is available on Windows behind the flag --enable-features=PlatformAudioEncoder

You can track the progress of that implementation at https://bugs.chromium.org/p/chromium/issues/detail?id=1259883 and are welcome to begin testing!

rafael2k commented 1 year ago

Any way to get a chrome version with AAC support?

dalecurtis commented 1 year ago

Stable macOS and Windows versions support AAC encoding. Please file bugs at https://crbug.com/new if you run into any issues.

tlecoz commented 1 year ago

Hello Dale Curtis,

It s not a bug but as far as i know there is no working exemple of an audio/video transcoding that output a mp4 file.

It could be very helpful if you could provide one.

Le jeu. 12 janv. 2023 à 18:49, Dale Curtis @.***> a écrit :

Stable macOS and Windows versions support AAC encoding. Please file bugs at https://crbug.com/new if you run into any issues.

— Reply to this email directly, view it on GitHub https://github.com/w3c/webcodecs/issues/259#issuecomment-1380782126, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACCTML3FQNRA642TNXPJD3WSA73JANCNFSM45UEYD4Q . You are receiving this because you commented.Message ID: @.***>

rafael2k commented 1 year ago

I just would like help with a sample to create an AAC in ADTS format, audio only.

dalecurtis commented 1 year ago

You should just be able to configure the encoder for aac and attach ADTS headers to the output samples. Is that not working?

mp4box.js should support aac muxing, but I haven't tried it.

rafael2k commented 1 year ago

I don't need / want mp4box.js. WebCodecs standard already provides AAC in ADTS format.

rafael2k commented 1 year ago

I think I should use something like this right:

        const config = {
          numberOfChannels: music_buffer.numberOfChannels,
          sampleRate: sampleRate,
          codec: "mp4a.40.2",
          aac: { format: 'adts' },
          bitrate: 128000
        };
dalecurtis commented 1 year ago

Ah, we forgot to implement https://www.w3.org/TR/webcodecs-aac-codec-registration/#aac-encoder-config -- filed https://bugs.chromium.org/p/chromium/issues/detail?id=1407013

You can pretty simply append an adts header in javascript using the current implementation though.

rafael2k commented 1 year ago

Thanks Dale! Have a nice day!

rafael2k commented 1 year ago

One more question: you mentioned mp4box.js, which is great, but do you also know about some javacript muxer for webm/matroska format? I saw one in this repo in the examples folder, but it seems a video-only muxer. I think I'll use Opus for now, as its implementation in WebCodecs seems a bit more mature and works on Linux / MacOS / Windows and Android already. But I also could find no sample which encodes to Opus and mux to webm.

dalecurtis commented 1 year ago

Unfortunately I'm not aware of a webm/mkv muxer of similar quality to mp4box.js. Folks have just found a few random ones lurking around GitHub. It shouldn't be too hard to add audio to a video only muxer. It's should only be adding the audio related EBML fields.

rafael2k commented 1 year ago

Yay already committed, tks Dale! https://chromium.googlesource.com/chromium/src/+/5bb89226f7e788fef09f0154c853cb136c008dc1 Which version will have it already? Nightly already picks it?

Cheers!

rafael2k commented 1 year ago

I think it would be nice to have a sample here with a simple audio encoding software to AAC/ADTS and let the audio be downloaded.

Djuffin commented 1 year ago

AAC/ADTS switch in Chromium is still work in progress. I'll put a link to a sample here when it's done.

rafael2k commented 1 year ago

Thanks Eugene! I wanted to say that it would be nice to have some sample code for an audio encoding pipeline for AAC in ADTS format here: https://github.com/w3c/webcodecs/tree/main/samples

rafael2k commented 1 year ago

Bug fixed! https://bugs.chromium.org/p/chromium/issues/detail?id=1407013

Do you when this code will roll to chrome nighties?

dalecurtis commented 1 year ago

Looks like 112.0.5600.0 per https://storage.googleapis.com/chromium-find-releases-static/5ef.html#5ef816ccd77177d316eb89317ee060fc211fbb59

rafael2k commented 1 year ago

Yay, it works on Chrome on Windows, but not in Chrome on Android. Am I doing something wrong? My test page: https://abradig.org.br/colmena-aac/test-aac.html

Djuffin commented 1 year ago

Currently, Chromium only supports AAC encoding on Windows and MacOS

rafael2k commented 1 year ago

Right. Do you think there is a chance in the future it also supports it in Android, as the Fraunhofer AAC implementation is there?

rafael2k commented 1 year ago

ffaac (ffmpeg aac implementation) is also complete and can support all mpeg 4 aac profiles listed in the standard, so Linux could also benefit from this.

jiyeyuran commented 9 months ago

good news, Chromium(120) is about to support AAC on Android. Check this CL: https://chromium-review.googlesource.com/c/chromium/src/+/4950497

rafael2k commented 9 months ago

Yay! Support on Windows, Mac and Android. Only Linux missing now! Issue here: https://bugs.chromium.org/p/chromium/issues/detail?id=1502444 : )

tlecoz commented 9 months ago

Great news ! Thanks for sharing !

tguilbert-google commented 9 months ago

Yes, please open a bug on crbug.com if you run into issues with it. Thanks!