MDN’s new design is in Beta! A sneak peek:

为 HTML 5 视频提供的 DASH 自适应串流


经由 HTTP 的动态自适应串流(DASH)是一种自适应串流协议。 这意味着它使得视频串流能基于网络性能来调整比特率,以保证视频流畅播放。


Firefox 21 包含了针对 HTM5 WebM 视频的 DASH 实现,但默认没有启用。可以通过在“about:config”里调整“media.dash.enabled”首选项来开启。

Firefox 23 移除了针对 HTML5 WebM 视频的 DASH 实现。此功能将被 媒体源扩展 API(MSE) 的实现取代。MSE 可实现通过 JavaScript 库(例如 dash.js)来提供对 DASH 的支持。详情参见 Bug 778617

使用 DASH - 服务端

First you'll need to convert your WebM video to a DASH manifest with the accompanying video files in various bit rates. To start with you'll need:

1. Use your existing WebM file to create one audio file and multiple video files.

For example:

The file can be any container with at least one audio and one video stream that can be decoded by ffmpeg,

Create the audio using:

ffmpeg -i -vn -acodec libvorbis -ab 128k my_audio.webm

Create each video variant.

ffmpeg -i -c:v libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1  -f webm -dash 1 \
-an -vf scale=160:190 -b:v 250k video_160x90_250k.webm 

ffmpeg -i -c:v libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1  -f webm -dash 1 \
-an -vf scale=320:180 -b:v 500k video_320x180_500k.webm

ffmpeg -i -c:v libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1  -f webm -dash 1 \
-an -vf scale=640:360 -b:v 750k  video_640x360_750k.webm

ffmpeg -i -c:v libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1  -f webm -dash 1 \
-an -vf scale=640:360 -b:v 1000k  video_640x360_1000k.webm

ffmpeg -i -c:v libvpx-vp9 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1  -f webm -dash 1 \
-an -vf scale=1280:720 -b:v 1500k  video_1280x720_1500k.webm

Or do it in all in one command.

ffmpeg -i -c:v libvpx-vp9 -keyint_min 150 \
-g 150 -tile-columns 4 -frame-parallel 1  -f webm -dash 1 \
-an -vf scale=160:190 -b:v 250k video_160x90_250k.webm \
-an -vf scale=320:180 -b:v 500k video_320x180_500k.webm \
-an -vf scale=640:360 -b:v 750k  video_640x360_750k.webm \
-an -vf scale=640:360 -b:v 1000k  video_640x360_1000k.webm \
-an -vf scale=1280:720 -b:v 1500k  video_1280x720_1500k.webm

2. Align the clusters to enable switching at cluster boundaries.

For video:

samplemuxer -i my_video-250kbps.webm -o my_video-250kbps-final.webm

Although we don't switch audio streams, it's still necessary to run it through samplemuxer to ensure a cues element is added. Note: to be compatible with playing on Chrome, it is suggested to change the track number to something other than the one in the video files, most likely 0.

samplemuxer -i my_audio.webm -o my_audio-final.webm -output_cues 1 -cues_on_audio_track 1 -max_cluster_duration 2 -audio_track_number

3. Create the manifest file:

webm_dash_manifest -o my_video_manifest.mpd \
  -as id=0,lang=eng \
  -r id=0,file=my_video-250kbps-final.webm \
  -r id=1,file=my_video-100kbps-final.webm \
  -r id=2,file=my_video-50kbps-final.webm \
  -as id=1,lang=eng \
  -r id=4,file=my_audio-final.webm

Put the manifest and the associated video files on your web server or CDN. DASH works via HTTP, so as long as your HTTP server supports byte range requests, and it's set up to serve .mpd files with mimetype="application/dash+xml", then you're all set.

Using DASH - Client Side

You'll want to modify your web page to point to the DASH manifest first, instead of directly to a particular video file:

  <source src="movie.mpd">
  <source src="movie.webm">
  Your browser does not support the video tag.

That's it! If DASH is supported by the browser, your video will now stream adaptively.

WebM DASH Specification at The WebM Project

DASH Industry Forum


 此页面的贡献者: xcffl
 最后编辑者: xcffl,