音频/mp4;编解码器="mp4a.40.2";无法在Chrome和Firefox中播放 [英] audio/mp4; codecs="mp4a.40.2" not playing in Chrome and Firefox

查看:1680
本文介绍了音频/mp4;编解码器="mp4a.40.2";无法在Chrome和Firefox中播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我想将要在我的网站上流式传输的音频转换为audio/mp4; codecs="mp4a.40.2".

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

使用 ffmpeg-cli-wrapper ,我正在使用此命令转换上传的音频文件在这里:

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

在客户端上,我正在像这样创建SourceBuffer:

On the client I am creating a SourceBuffer like this:

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

错误是:

Chrome浏览器:

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.

这是有趣的部分:

如果我使用audio/aac作为mime-type创建SourceBuffer:

Here comes the fun part:

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

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

音频可以在Chrome上正确播放,但Firefox会显示:

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
                                                             ^^^ 

使用audio/mp4; codecs="mp4a.40.2"时,Chrome/Firefox没有出现错误,但是音频没有播放.

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

推荐答案

在ffmpeg命令中,使用扩展名.m4a(或.mp4),而不是.aac:

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

.aac扩展名用于ADTS容器中的AAC,这不是Web上广泛使用或支持的格式. .m4a.mp4扩展名用于MP4容器中的AAC,这很常见.

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.

或者,如果出于某种原因您确实希望将文件命名为output.aac,但又希望其在MP4中包含AAC,那么您可以指定输出格式,而不是让ffmpeg根据文件名来猜测所需的格式.输出文件扩展名:

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

但是,如果您使用类似这样的非标准扩展名,则可能还需要更新Web服务器配置,以便其报告正确的媒体类型.

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.

这篇关于音频/mp4;编解码器="mp4a.40.2";无法在Chrome和Firefox中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆