为什么一些MP4文件不能通过HTML5播放? [英] Why won't some MP4 files play via HTML5?

查看:474
本文介绍了为什么一些MP4文件不能通过HTML5播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

<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?

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

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

推荐答案

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

mp4 is only the container format. 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.

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

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

但是它没有解决一个问题:没有所有浏览器都支持单视频编解码器。 (另请参阅维基百科:HTML5视频:Browser_support

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

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

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.

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

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:

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

Something I used to help a friend publish a few videos on his little blog is this shell script using ffmpeg for 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.

这篇关于为什么一些MP4文件不能通过HTML5播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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