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

喜你入骨 提交于 2020-11-25 04:08:30

问题


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

  • https://stackoverflow.com/a/64432478/826983

回答1:


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.



来源:https://stackoverflow.com/questions/64412488/audio-mp4-codecs-mp4a-40-2-not-playing-in-chrome-and-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!