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

查看:66
本文介绍了音频/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"');

错误是:

铬:

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

火狐:

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


更新

更改命令后

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

Chrome/Firefox 在使用 audio/mp4 时不会报错;codecs="mp4a.40.2",但没有播放音频.

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,它不是网络上广泛使用或支持的格式..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

但如果您使用类似的非标准扩展程序,那么您可能还需要更新您的网络服务器配置,以便它报告正确的媒体类型.

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天全站免登陆