Html 为什么有些 MP4 文件不能通过 HTML5 播放?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11588654/
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-29 01:46:01  来源:igfitidea点击:

Why won't some MP4 files play via HTML5?

htmlvideohtml5-video

提问by Frank Lv

It's strange, some MP4 files will play in HTML5, but others won't. Here is a test page http://psdtucss.com/test/test2.html, open it in Chrome 19.0.1084.46 m. The first MP4 plays, but the other one won't. What's the reason. The code is very simple:

奇怪的是,有些 MP4 文件可以在 HTML5 中播放,而有些则不能。这是一个测试页面http://psdtucss.com/test/test2.html,在 Chrome 19.0.1084.46 m 中打开它。第一个 MP4 播放,但另一个不播放。什么原因。代码非常简单:

<h3>the first mp4 file can play</h3> 
<p><video width="640" height="264" controls="controls"><source src="1.mp4" type="video/mp4" />Your browser does not support the video tag.</video></p> 
<h3>but the other can't play</h3> 
<p><video width="640" height="264" controls="controls"><source src="2.mp4" type="video/mp4" />Your browser does not support the video tag.</video></p>

How can I fix this?

我怎样才能解决这个问题?

I tried videojs, but still some MP4 files won't play. Test page is here: http://psdtucss.com/test/test.html

我试过 videojs,但仍有一些 MP4 文件无法播放。测试页面在这里:http: //psdtucss.com/test/test.html

回答by zpea

mp4 is only the containerformat. It may contain video and audio in a number of different codecs. Players (including those in a browser) need to support the container format and all of the used codecs in order to play a video properly.

mp4 只是容器格式。它可能包含许多不同编解码器中的视频和音频。播放器(包括浏览器中的播放器)需要支持容器格式和所有使用的编解码器才能正确播放视频。

Using VideoJS is definitely a good idea, it handles a lot of browser-specific workarounds for you.

使用 VideoJS 绝对是一个好主意,它为您处理了许多特定于浏览器的解决方法。



However it does not solve one problem: There is no single video codec supported in all browsers. (See also Wikipedia: HTML5 video: Browser_support)

然而它并没有解决一个问题:所有浏览器都不支持单一的视频编解码器。(另见维基百科:HTML5 视频:Browser_support

The practical solution probably is to provide two versions: h264 in a mp4 container and what is usually called webm (VP8 video and vorbis audio in a specific Matroska container). With those two you cover all major browsers.

实际的解决方案可能是提供两个版本:mp4 容器中的 h264 和通常称为 webm 的版本(特定 Matroska 容器中的 VP8 视频和 vorbis 音频)。有了这两个,您就可以覆盖所有主要浏览器。



For video conversion/recoding there are some tools and services available. I have no idea about your operating system or requirements. So just as a wild guess:

对于视频转换/重新编码,有一些可用的工具和服务。我不知道您的操作系统或要求。所以就像一个疯狂的猜测:

Something I used to help a friend publish a fewvideos on his little blog is this shell script using ffmpegfor conversion. It still leaves a lot of potential for improvement (in all of video quality, performance and coding) but should be good enough to get started.

我曾经帮助一个朋友在他的小博客上发布一些视频的是这个使用 ffmpeg进行转换的shell 脚本。它仍然有很大的改进潜力(在所有视频质量、性能和编码方面),但应该足以开始使用。

回答by Dennis

The first video uses h264 encoding which is supported by everything except Firefox and Opera. The second video uses the MPEG-4 video codec which is not supported by browsers. The only widely supported video codecs are Theora, H.264 and VP8.

第一个视频使用 h264 编码,除 Firefox 和 Opera 外,所有设备都支持该编码。第二个视频使用浏览器不支持的 MPEG-4 视频编解码器。唯一得到广泛支持的视频编解码器是 Theora、H.264 和 VP8。

MPEG-4 Part 2video codec is different from the MPEG-4 Part 14container format

MPEG-4 Part 2视频编解码器不同于MPEG-4 Part 14容器格式

回答by Sany Liew

Your video 1.mp4 is encoded using h.264 but video 2.mp4 is not. get MediaInfo to check about it.

您的视频 1.mp4 使用 h.264 编码,但视频 2.mp4 不是。让 MediaInfo 来检查一下。

回答by Peter Ritchie

MP4 supports multiple codecs. Some players don't support all codecs (some codes require licensing, or some codecs were released after the browser was written).

MP4 支持多种编解码器。有些播放器不支持所有的编解码器(有些代码需要授权,或者有些编解码器是在浏览器编写后发布的)。