“无法播放媒体.没有用于请求格式的解码器流行的Big Buck Bunny mp4视频上 [英] "Cannot play media. No decoders for requested formats" on popular Big Buck Bunny mp4 video

查看:85
本文介绍了“无法播放媒体.没有用于请求格式的解码器流行的Big Buck Bunny mp4视频上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MediaSource 播放我的视频:

I'm trying to use MediaSource to play my video:

const videoTag = document.getElementById('theVideoId');
const mimeCodec = 'video/mp4; codecs="' + audioCodec + ', ' + videoCodec + '"';

if (!('MediaSource' in window) || !MediaSource.isTypeSupported(mimeCodec)) {
    console.error('Unsupported MIME type or codec: ', mimeCodec);
}

const mediaSource = new MediaSource();

videoTag.src = URL.createObjectURL(mediaSource);
videoTag.crossOrigin = 'anonymous';

await new Promise((resolve, reject) => {
    mediaSource.addEventListener('sourceopen', function (_) {
        console.log(this.readyState); // open
        resolve();
    });
});

const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);

//....

sourceBuffer.appendBuffer(new Uint8Array(chunk));

使用上述代码,某些视频可以正常播放.其他人发出警告:

With the above code some videos play just fine. Others, give a warning:

Cannot play media. No decoders for requested formats: video/mp4; codecs="mp4a.40.2 avc1.4d400c", video/mp4; codecs="mp4a.40.2 avc1.4d400c" 

有趣的是,我在上面的代码中的 if 语句

What is interesting is that my if statement in the code above

if (!('MediaSource' in window) || !MediaSource.isTypeSupported(mimeCodec)) {

支持

类似于 mimeCodec 源的行为,因为它不会引发 Unsupported MIME type或codec 错误.我也是无法播放媒体的代表.没有解码器用于请求的格式错误,因为在我的Google Photos帐户中播放的视频完全相同,因此我知道我的浏览器确实支持该视频.

acts like the mimeCodec source is supported because it does not throw the Unsupported MIME type or codec error. I'm also skeptial of the Cannot play media. No decoders for requested formats error because the exact same video plays on my Google Photos account so I know my browser does support it.

我该如何解决?有没有一种方法可以添加一个解码器".本地不支持的 codec 类型,还是可以将视频重新格式化为更常见的受支持的 codec 类型?该视频是常见的 Big Buck Bunny mp4 视频之一,因此我还想知道我的代码是否缺少某些内容,因为该视频似乎得到了广泛支持.

How can I solve it? Is there a way to add in a "decoder" for codec types not natively supported or can I re-format the video into a more common supported codec type? The video is one of the common Big Buck Bunny mp4 videos, so I'm also wondering if my code has something missing since that video seems widely supported.

推荐答案

MediaSource扩展仅支持

MediaSource extension only supports fragmented mp4, the file hosted by w3school is not fragmented.

请参见此MDN文章正确重新编码的方法.

See this MDN article for ways to reencode it properly.

这篇关于“无法播放媒体.没有用于请求格式的解码器流行的Big Buck Bunny mp4视频上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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