Html .mp4 文件不在 Chrome 中播放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25131906/
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
.mp4 file not playing in chrome
提问by Savinay
I want to show a video on my website. I have created a .mp4 file and using the HTML5 video tag to add it to the html.
我想在我的网站上播放视频。我创建了一个 .mp4 文件并使用 HTML5 视频标签将其添加到 html。
The problem is that it is not being displayed in chrome. I would also like to know how I can replay it again and again.
问题是它没有以 chrome 显示。我也想知道如何一次又一次地重播。
回答by Romualds Cirsis
After running into the same issue - here're some of my thoughts:
在遇到同样的问题后 - 这是我的一些想法:
- due to Chrome removing support for h264, on some machines, mp4 videos encoded with it will either not work (throwing an Parser error when viewing under Firebug/Network tab - consistent with issue submitted here), or crash the browser, depending upon the encoding settings
- it isn't consistent - it entirely depends upon the codecs installed on the computer - while I didn't encounter this issue on my machine, we did have one in the office where the issue occurred (and thus we used this one for testing)
- it might to do with Quicktime / divX settings (the machine in question had an older version of Quicktime than my native one - we didn't want to loose our testing pc though, so we didn't update it).
- 由于 Chrome 取消了对 h264 的支持,在某些机器上,使用它编码的 mp4 视频将无法工作(在 Firebug/Network 选项卡下查看时抛出解析器错误 - 与此处提交的问题一致),或者使浏览器崩溃,具体取决于编码设置
- 它不一致 - 它完全取决于计算机上安装的编解码器 - 虽然我没有在我的机器上遇到这个问题,但我们在发生问题的办公室里确实有一个(因此我们用这个来测试)
- 这可能与 Quicktime / divX 设置有关(有问题的机器的 Quicktime 版本比我的原生版本旧 - 不过我们不想丢失我们的测试电脑,所以我们没有更新它)。
As it affects only Chrome (other browsers work fine with VideoForEverybody solution) the solution I've used is:
由于它仅影响 Chrome(其他浏览器与 VideoForEverybody 解决方案配合良好),我使用的解决方案是:
for every mp4 file, create a Theora encoded mp4 file (example.mp4 -> example_c.mp4) apply following js:
对于每个 mp4 文件,创建一个 Theora 编码的 mp4 文件(example.mp4 -> example_c.mp4)应用以下 js:
if (window.chrome)
$("[type=video\\/mp4]").each(function()
{
$(this).attr('src', $(this).attr('src').replace(".mp4", "_c.mp4"));
});
Unfortunately it's a bad Chrome hack, but hey, at least it works.
不幸的是,这是一个糟糕的 Chrome 黑客,但嘿,至少它有效。
Source: user: eithedog
来源:用户:eithedog
This also can help: chrome could play html5 mp4 video but html5test said chrome did not support mp4 video codec
这也有帮助:chrome 可以播放 html5 mp4 视频,但 html5test 说 chrome 不支持 mp4 视频编解码器
Also check your version of crome here: html5test
还要在这里检查您的 crome 版本:html5test
回答by Mahesh
I too had the same issue. I changed the codec to H264-MPEG-4 AVC and the videos started working in HTML5/Chrome.
我也有同样的问题。我将编解码器更改为 H264-MPEG-4 AVC,视频开始在 HTML5/Chrome 中工作。
Option selected in converter: H264-MPEG-4 AVC, Codec visible in VLC player: H264-MPEG-4 AVC (part 10) (avc1)
在转换器中选择的选项:H264-MPEG-4 AVC,VLC 播放器中可见的编解码器:H264-MPEG-4 AVC(第 10 部分)(avc1)
Hope it helps...
希望能帮助到你...
回答by TOPSie
This started out as an attempt to cast video from my pc to a tv (with subtitles) eventually using Chromecast. And I ended up in this "does not play mp4" situation. However I seemed to have proved that Chrome will play (exactly the same) mp4 as long as it isn't wrapped in html(5) So here is what I have constructed. I have made a webpage under localhost and in there is a default.htm which contains:-
这开始是为了最终使用 Chromecast 将视频从我的电脑投射到电视(带字幕)。我最终陷入了这种“不播放 mp4”的情况。但是,我似乎已经证明 Chrome 会播放(完全相同)mp4,只要它不包含在 html(5) 中,所以这就是我构建的内容。我在 localhost 下创建了一个网页,其中有一个 default.htm,其中包含:-
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<video controls >
<source src="sample.mp4" type="video/mp4">
<track kind="subtitles" src="sample.vtt" label="gcsubs" srclang="eng">
</video>
</body>
</html>
the video and subtitle files are stored in the same folder as default.htm
视频和字幕文件与default.htm 存储在同一文件夹中
I have the very latest version of Chrome (just updated this morning)
我有最新版本的 Chrome(今天早上刚更新)
When I type the appropriate localhost... into my Chrome browser a black square appears with a "GO" arrow and an elapsed time bar, a mute button and an icon which says "CC". If I hit the go arrow, nothing happens (it doesn't change to "pause", the elapsed time doesn't move, and the timer sticks at 0:00. There are no error messages - nothing!
当我在 Chrome 浏览器中键入适当的 localhost... 时,会出现一个带有“GO”箭头和经过时间条的黑色方块、一个静音按钮和一个显示“CC”的图标。如果我点击前进箭头,则什么也不会发生(它不会更改为“暂停”,经过的时间不会移动,并且计时器停留在 0:00。没有错误消息 - 什么都没有!
(note that if I input localhost.. to IE11 the video plays!!!!
(请注意,如果我输入 localhost.. 到 IE11,视频会播放!!!!
In Chrome if I enter the disc address of sample.mp4 (i.e. C:\webstore\sample.mp4 then Chrome will play the video fine?.
在 Chrome 中,如果我输入 sample.mp4 的光盘地址(即 C:\webstore\sample.mp4,那么 Chrome会正常播放视频?。
This last bit is probably a working solution for Chromecast except that I cannot see any subtitles. I really want a solution with working subtitles. I just don't understand what is different in Chrome between the two methods of playing mp4
最后一点可能是 Chromecast 的有效解决方案,只是我看不到任何字幕。我真的想要一个带有工作字幕的解决方案。我只是不明白 Chrome 中两种播放 mp4 的方法有什么不同
回答by lakewood
Encountering the same problem, I solved this by reconverting the file with default mp4 settings in iMovie.
遇到同样的问题,我通过在 iMovie 中使用默认 mp4 设置重新转换文件解决了这个问题。
回答by Dzenis H.
I was actually running into some strange errors with mp4's a while ago. What fixed it for me was re-encoding the video using known supported codecs (H.264 & MP3).
不久前,我实际上在使用 mp4 时遇到了一些奇怪的错误。为我修复的是使用已知支持的编解码器(H.264 和 MP3)重新编码视频。
I actually used the VLC playerto do so and it worked fine afterward. I converted using the mentioned codecs H.264/MP3. That solved it for me.
我实际上使用了VLC 播放器来这样做,后来它工作得很好。我使用提到的编解码器H.264/MP3进行了转换。那为我解决了。
Maybe the problem is not in the format
but in the JavaScript
implementation of the play/ pause
methods. May I suggest visiting the following linkwhere Google developer explains it in a good way?
也许问题不在于方法,format
而在于方法的JavaScript
实现play/ pause
。我可以建议访问以下链接,谷歌开发人员以一种很好的方式解释它吗?
Additionally, you could choose to use the newer webp
format, which Chrome supports out of the box, but be careful with other browsers. Check the support for it before implementation. Here's a linkthat describes the mentioned format.
此外,您可以选择使用较新的webp
格式,Chrome 支持开箱即用,但要小心使用其他浏览器。在实施之前检查对它的支持。这是一个描述上述格式的链接。
On that note: I've created a small script
that easily converts all standard formats to webp
. You can easily configure it to fit your needs. Here's the Github repoof the same projects.
关于这一点:我创建了一个script
可以轻松将所有标准格式转换为webp
. 您可以轻松配置它以满足您的需求。这是相同项目的Github 存储库。