Stefan Falk
Stefan Falk

Reputation: 25457

audio/mp4; codecs="mp4a.40.2" not playing in Chrome and Firefox

It seems I want to convert audios, which I want to stream on my website, to audio/mp4; codecs="mp4a.40.2".

Using ffmpeg-cli-wrapper, I am converting my uploaded audio files with this command here:

ffmpeg -i /tmp/input.any -acodec aac -b:a 256000 /tmp/output.aac

On the client I am creating a SourceBuffer like this:

this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/mp4; codecs="mp4a.40.2"');

The errors are:

Chrome:

NotSupportedError: Failed to load because no supported source was found.

Firefox:

NotSupportedError: The media resource indicated by the src attribute or assigned media provider object was not suitable.

Here comes the fun part:

If I create the SourceBuffer using audio/aac as mime-type:

this.sourceBuffer = this.mediaSource.addSourceBuffer('audio/aac');

the audio gets played correctly on Chrome but Firefox says:

MediaSource.addSourceBuffer: Type not supported in MediaSource

Update

After changing the command to

ffmpeg -i /tmp/input.any -acodec aac -b:a 256000 /tmp/output.mp4
                                                             ^^^ 

Chrome/Firefox do not give an error when using audio/mp4; codecs="mp4a.40.2", but the audio is not being played.


See

Upvotes: 2

Views: 13961

Answers (2)

rsc
rsc

Reputation: 10679

I was having a similar issue where my fMP4 played fine if used directly as src inside the video tag, but it didn't play when used via MediaSource Extensions. My problem was that my AAC frame in the fMP4 was with the ADTS header and it appears that MSE doesn't like those headers. So, I removed the ADTS header from each AAC frame and it worked fine. (I already had the Audio Specific Config added in my ESDS box, so I could remove the ADTS header without issue.)

Upvotes: 0

mark4o
mark4o

Reputation: 60933

In your ffmpeg command, use the extension .m4a (or .mp4), not .aac:

ffmpeg -i /tmp/input.any -acodec aac -b:a 256000 /tmp/output.m4a

The .aac extension is used for AAC in the ADTS container, which is not a format that is widely used or supported on the web. The .m4a or .mp4 extension is used for AAC in the MP4 container, which is far more common.

Or, if for some reason you really want the file to be named output.aac but yet want it to contain AAC in MP4, then you can specify the output format instead of having ffmpeg guess the format that you want based on the output file extension:

ffmpeg -i /tmp/input.any -acodec aac -b:a 256000 -f mp4 /tmp/output.aac

But if you use a non-standard extension like that then you may also need to update your web server configuration so that it will report the correct media type.

Upvotes: 5

Related Questions