HTML5 - 如何流式传输大型 .mp4 文件? [英] HTML5 - How to stream large .mp4 files?

查看:36
本文介绍了HTML5 - 如何流式传输大型 .mp4 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个非常基本的 html5 页面,该页面加载 20MB 的 .mp4 视频.浏览器似乎需要下载整个内容,而不仅仅是播放视频的第一部分并在其余部分进行流式传输.

这篇文章是我在搜索时找到的最接近的东西... 我尝试了 Hand Brake 和 Data Go Round 都没有效果:

关于如何做到这一点或是否可能有任何想法?

这是我正在使用的代码:

解决方案

  1. 确保moov(元数据)在mdat(音频/视频数据).这也称为快速启动".或网络优化".例如,Handbrake 有一个Web Optimized"复选框ffmpegavconv 有输出选项 -movflags faststart.
  2. 确保您的网络服务器报告正确的内容类型(视频/mp4).
  3. 确保您的网络服务器配置为服务字节范围请求.
  4. 确保您的网络服务器没有在 mp4 文件的压缩之上应用 gzip 或 deflate 压缩.

您可以使用 curl -I http://yoursite/video.mp4 或使用浏览器中的开发工具 (ChromeFirefox)(如果它被缓存).HTTP 响应标头应包括 Content-Type: video/mp4Accept-Ranges: bytes,并且没有 Content-Encoding:.>

I'm trying to setup a very basic html5 page that loads a .mp4 video that is 20MB. It appears that the browser needs to download the entire thing rather than just playing the first part of the video and streaming in the rest.

This post is the closest thing I've found while searching... I tried both Hand Brake and Data Go Round by neither appeared to make a difference:

Any ideas on how to do this or if it's possible?

Here is the code I'm using:

<video controls="controls">
    <source src="/video.mp4" type="video/mp4" />
    Your browser does not support the video tag.
</video>

解决方案

  1. Ensure that the moov (metadata) is before the mdat (audio/video data). This is also called "fast start" or "web optimized". For example, Handbrake has a "Web Optimized" checkbox, and ffmpeg and avconv have the output option -movflags faststart.
  2. Ensure that your web server is reporting the correct Content-Type (video/mp4).
  3. Ensure that your web server is configured to serve byte range requests.
  4. Ensure that your web server is not applying gzip or deflate compression on top of the compression in the mp4 file.

You can check the headers being sent by your web server using curl -I http://yoursite/video.mp4 or using the developer tools in your browser (Chrome, Firefox) (reload the page if it is cached). The HTTP Response Header should include Content-Type: video/mp4 and Accept-Ranges: bytes, and no Content-Encoding:.

这篇关于HTML5 - 如何流式传输大型 .mp4 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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