Html HTML5 <video> 可以播放 .mkv 文件吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9622726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:00:18  来源:igfitidea点击:

HTML5 <video> can play .mkv files?

htmlhtml5-videomkv

提问by Mark

So I accidentally opened an mkv video file with Chrome, and to my surprise it played it using the native player:

所以我不小心用 Chrome 打开了一个 mkv 视频文件,令我惊讶的是它使用本机播放器播放:

<video src="video.mkv"></video>

It was playing perfectly. HTML5 video supports matroska container?

它玩得很完美。HTML5 视频支持 matroska 容器吗?

回答by JJJ

HTML5 doesn't support anyvideo formats, or rather HTML5 doesn't specify what formats browsers should support. It's up to the browsers to decide which formats they choose to support. Apparently Chrome plays .mkv, but I wouldn't be surprised if other browsers didn't play the same file.

HTML5 不支持任何视频格式,或者说 HTML5 没有指定浏览器应该支持什么格式。由浏览器决定他们选择支持哪些格式。显然 Chrome 播放 .mkv,但如果其他浏览器不播放相同的文件,我不会感到惊讶。

回答by Harry Lewis

The website has probably set the mimetype of the file to video/webm. Chrome will open this inline rather than forcing a download (because otherwise it doesnt know what to do with it or how to open it).

该网站可能已将文件的 mimetype 设置为 video/webm。Chrome 将内联打开此文件而不是强制下载(因为否则它不知道如何处理它或如何打开它)。

E.g., in apache this is done by using the AddType directive (can be done in a htaccess):

例如,在 apache 中,这是通过使用 AddType 指令完成的(可以在 htaccess 中完成):

    AddType video/webm .mkv

回答by Synergiance

I'd be surprised if browsers didn't support mkv, as the webm container is just a restricted version of the matroska format. Beyond that you'd have to check the codec of the video inside, and ensure your browser can handle that. If the video format is VP8 or VP9 and the audio is Opus or Vorbis it's webm compliant and might as well be renamed as such. Note that H.264, H.265 and MP3 are not webm compliant and you should avoid using that extension on files that include those formats, the video would still play but it would technically break the webm specification and is frowned upon.

如果浏览器不支持 mkv,我会感到惊讶,因为 webm 容器只是 matroska 格式的受限版本。除此之外,您还必须检查内部视频的编解码器,并确保您的浏览器可以处理。如果视频格式是 VP8 或 VP9,而音频是 Opus 或 Vorbis,则它是 webm 兼容的,也可以像这样重命名。请注意,H.264、H.265 和 MP3 不符合 webm,您应该避免在包含这些格式的文件上使用该扩展名,视频仍会播放,但在技术上会违反 webm 规范并且不受欢迎。