Html 如何在网络浏览器中播放 MKV 视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21192713/
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
How to playback MKV video in web browser
提问by Alex Meyer
I am trying to make a MKV video with a MPEG4 video codec and AC3 audio codec available to be played online using Mozilla or Chrome. I have tried multiple methods including native HTML5, which plays back the video but no audio and from what I've read AC3 is a proprietary codec so it is not included in the supported codecs. The code for that was as follows:
我正在尝试使用 MPEG4 视频编解码器和 AC3 音频编解码器制作可使用 Mozilla 或 Chrome 在线播放的 MKV 视频。我尝试了多种方法,包括本机 HTML5,它播放视频但没有音频,从我读过的内容来看,AC3 是一种专有编解码器,因此它不包含在支持的编解码器中。代码如下:
<video width='1024' height='768' controls autoplay>
<source src="path_to_src" type='video/x-matroska'</video>
I then tried to use the VLC web plugin (as I know VLC can play the files correctly) but have not yet gotten it to play any file, there doesn't seem to be a lot of consistency in the examples for using this method. Here is what I have tried so far using the VLC plugin:
然后我尝试使用 VLC 网络插件(因为我知道 VLC 可以正确播放文件)但还没有让它播放任何文件,使用这种方法的示例中似乎没有很多一致性。这是我到目前为止使用 VLC 插件尝试过的:
<embed type="application/x-vlc-plugin" version="VideoLAN.VLCPlugin.2"
width="1024" height="768" id="vlc" autoplay="yes" target="path_to_file"></embed>
The VLC page heresays to add this:
此处的 VLC 页面说要添加以下内容:
<object classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921"
codebase="http://download.videolan.org/pub/videolan/vlc/last/win32/axvlc.cab">
But the codebase doesn't seem to exist anymore and adding that classid to the code above has no affect on the playing of the file. Both methods result in the VLC player box being made but nothing ever getting played and the developer console doesn't show any errors.
但是代码库似乎不再存在,并且将那个 classid 添加到上面的代码中对文件的播放没有影响。这两种方法都会导致制作 VLC 播放器框,但没有播放任何内容,并且开发人员控制台不会显示任何错误。
So my question is does anyone know a workaround to get AC3 audio to play in the native HTML5 player or what the correct syntax is for the VLC web plugin? Or does anyone have a different player altogether they would recommend? Any and all help appreciated!
所以我的问题是有没有人知道让 AC3 音频在原生 HTML5 播放器中播放的解决方法,或者 VLC Web 插件的正确语法是什么?或者是否有人会推荐完全不同的播放器?任何和所有的帮助表示赞赏!
回答by Narendra Dharajiya
HTML5 does not support .mkv / Matroska files but you can use this code...
HTML5 不支持 .mkv / Matroska 文件,但您可以使用此代码...
<video>
<source src="video.mkv" type="video/mp4">
</video>
But it depends on the browser as to whether it will play or not. This method is known to work with Chrome.
但它是否会播放取决于浏览器。已知此方法适用于 Chrome。
回答by Amin
You can use this following code. work just on chrome browser.
您可以使用以下代码。仅在 chrome 浏览器上工作。
function failed(e) {
// video playback failed - show a message saying why
switch (e.target.error.code) {
case e.target.error.MEDIA_ERR_ABORTED:
alert('You aborted the video playback.');
break;
case e.target.error.MEDIA_ERR_NETWORK:
alert('A network error caused the video download to fail part-way.');
break;
case e.target.error.MEDIA_ERR_DECODE:
alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
break;
case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
alert('The video could not be loaded, either because the server or network failed or because the format is not supported.');
break;
default:
alert('An unknown error occurred.');
break;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Amin Developer!" />
<title>Untitled 1</title>
</head>
<body>
<p><video src="http://jell.yfish.us/media/Jellyfish-3-Mbps.mkv" type='video/x-matroska; codecs="theora, vorbis"' autoplay controls onerror="failed(event)" ></video></p>
<p><a href="YOU mkv FILE LINK GOES HERE TO DOWNLOAD">Download the video file</a>.</p>
</body>
</html>
回答by Alex Meyer
HTML5 and the VLC web plugin were a no go for me but I was able to get this work using the following setup:
HTML5 和 VLC 网络插件不适合我,但我能够使用以下设置完成这项工作:
DivX Web Player(NPAPI browsers only)
DivX Web Player(仅限NPAPI 浏览器)
And here is the HTML:
这是 HTML:
<embed id="divxplayer" type="video/divx" width="1024" height="768"
src ="path_to_file" autoPlay=\"true\"
pluginspage=\"http://go.divx.com/plugin/download/\"></embed>
The DivX player seems to allow for a much wider array of video and audio options than the native HTML5, so far I am very impressed by it.
DivX 播放器似乎允许比原生 HTML5 更广泛的视频和音频选项,到目前为止我对它印象非常深刻。
回答by JohnC
<video controls width=800 autoplay>
<source src="file path here">
</video>
This will display the video (.mkv) using Google Chrome browser only.
这将仅使用 Google Chrome 浏览器显示视频 (.mkv)。