WebM流的媒体源扩展appendBuffer以随机顺序 [英] Media Source Extensions appendBuffer of WebM stream in random order

查看:247
本文介绍了WebM流的媒体源扩展appendBuffer以随机顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从多个来源并行实现视频下载.但是,如果不遵循视频文件的顺序,MSE appendBuffer方法总是失败.

I am trying to achieve video downloading in parallel from multiple sources. However MSE appendBuffer method always fails when not following sequence order of video file.

我想按随机顺序附加各个部分,并尽快"播放视频. 我正在探索SourceBuffer模式属性以及timestampOffset.这些都没有帮助.

I would like to append parts in random order and play video "as soon as possible". I was exploring SourceBuffer mode property as well as timestampOffset. None of those were helpful.

我想知道我拥有的源webm文件是否可以以不支持的格式"来执行此任务(顺序方法可以正常工作).

I am wondering if source webm file i have could be in "not supported format" for such a task (sequential approach works fine).

源视频文件

谢谢您的任何建议.

更新: 我尝试分析众所周知的示例视频文件,我发现有可能将其部分乱序地添加.似乎有必要遵循集群字节范围:

UPDATE: I tried to analyse well known example video file and i figured out that it is possible to append parts of it out of order. Seems like it is necessary to follow Cluster byte ranges:

<Cluster type="list" offset="4357">
  <Timecode type="uint" value="0"/>
  <SimpleBlock type="binary" size="7723" trackNum="1" timecode="0" presentationTimecode="0" flags="80"/>
  <SimpleBlock type="binary" size="5" trackNum="2" timecode="0" presentationTimecode="0" flags="80"/>
  ...
</Cluster>
<Cluster type="list" offset="16187">
  <Timecode type="uint" value="385"/>
  <SimpleBlock type="binary" size="5" trackNum="2" timecode="0" presentationTimecode="385" flags="80"/>
  <SimpleBlock type="binary" size="4968" trackNum="1" timecode="13" presentationTimecode="398" flags="80"/>
  ...
</Cluster>

推荐答案

在研究了webm格式规范之后,编译了libwebm工具并研究了DASH,我最终弄清楚了如何使MSE appendBuffer以任何顺序工作!

After digging into webm format specification, compiling libwebm tools and studying DASH i finally figured out how to make MSE appendBuffer working in any order!

  1. ffmpeg -i result.webm -g 10 -c:v libvpx resultClusters.webm(也可以使用libvpx-vp9)
  2. mkvmuxer_sample -i resultClusters.webm -o resultRepaired.webm
  3. mse_json_manifest resultRepaired.webm >> manifest.json

您将在stdout上获得类似的内容:

You will get on stdout something like:

{
  "type": "video/webm; codecs=\"vp8\"",
  "duration": 27771.000000,
  "init": { "offset": 0, "size": 258},
  "media": [
    { "offset": 258, "size": 54761, "timecode": 0.000000 },
    { "offset": 55019, "size": 166431, "timecode": 2.048000 },
    { "offset": 221450, "size": 49258, "timecode": 4.130000 },
    { "offset": 270708, "size": 29677, "timecode": 6.148000 },
    { "offset": 300385, "size": 219929, "timecode": 8.232000 },
    { "offset": 520314, "size": 25132, "timecode": 10.335000 },
    { "offset": 545446, "size": 180777, "timecode": 12.440000 },
    { "offset": 726223, "size": 76107, "timecode": 14.471000 },
    { "offset": 802330, "size": 376557, "timecode": 14.794000 },
    { "offset": 1178887, "size": 247138, "timecode": 16.877000 },
    { "offset": 1426025, "size": 78468, "timecode": 18.915000 },
    { "offset": 1504493, "size": 25614, "timecode": 20.991000 },
    { "offset": 1530107, "size": 368277, "timecode": 23.093000 },
    { "offset": 1898384, "size": 382847, "timecode": 25.097000 },
    { "offset": 2281231, "size": 10808, "timecode": 27.135000 }
  ]
}

现在您要做的就是首先加载元数据xhr.setRequestHeader("Range", "bytes=0-257");,然后在 ANY ORDER 中所有其他段.例如.第二段范围是55019-221449个字节.

Now all you have to do is firstly load metadata xhr.setRequestHeader("Range", "bytes=0-257"); and then in ANY ORDER all other segments. E.g. second segment range is 55019-221449 bytes.

说明:

最重要的是 ffmpeg 重新编码,并将帧组设置为您想要的群集大小.在此示例中,我选择了非常低的阈值(每10帧),但是您可以选择更高的导致生成的簇更少(媒体"数组中的项目更少).

The most important thing is ffmpeg reencoding with group of frames set to the size of cluster you would like to have. In this example i choose pretty low threshold (each 10 frames) but you can choose higher causing fewer clusters are generated (less items in "media" array).

此后,您必须以经典方式(使用 libwebm 中的 sample_muxer )修复提示,然后就可以开始使用了.

After that you have to fix cues in the classic way (using sample_muxer from libwebm) and you are ready to go.

经过以下测试:Chrome 51,Firefox 47.

Tested on: Chrome 51, Firefox 47.

这篇关于WebM流的媒体源扩展appendBuffer以随机顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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