如何为HLS创建字节范围的m3u8播放列表? [英] How to create byte-range m3u8 playlist for HLS?

查看:367
本文介绍了如何为HLS创建字节范围的m3u8播放列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple 举个例子支持HLS的m3u8文件中的字节范围段

#EXTM3U
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-VERSION:4
#EXTINF:10.0,
#EXT-X-BYTERANGE:75232@0
media.ts
#EXTINF:10.0,
#EXT-X-BYTERANGE:82112@752321
media.ts 
#EXTINF:10.0, 
#EXT-X-BYTERANGE:69864
media.ts

但是我不知道如何为给定的.ts文件创建这样的播放列表. 有什么工具吗?

解决方案

类似

ffprobe -show_frames media.ts -print_format json

提供了有关框架的足够信息来构建这样的播放列表,尽管构建该列表需要一些脚本.

如果我成功使用该方法,我将使用脚本更新此答案.

更新:

以下是到目前为止我找到的几个有用的链接:

用于生成iframe播放列表的Bash脚本-需要一些优化,因为它称为ffprobe多次

iframe-playlist-generator -可用于生成python的项目iframe播放列表中的普通播放列表

这并不是我最初搜索的内容,但是I-Frame播放列表类似于字节范围的播放列表,并且更适合我的任务,因此我将使用这两个项目作为参考/起点创造一些更适合我的东西.

项目实际上使用不同的方法来查找I-Frame的大小-bash脚本仅使用ffprobe在pkt_size中显示的内容,而python项目通过将大小计算为数据包位置的差异并向其中添加188,从而添加了一些伏都教匹配来自Apple的示例播放列表. 188个字节是mpeg-ts数据包的大小,可能与某种原因有关,但是我还不了解如何做到这一点.大小计算上的这种差异会导致生成不同的播放列表,其中的一个播放列表可能在某种程度上是不正确的,但实际上VLC可以同时播放两个播放列表,因此没有任何问题,因此,我将坚持使用更简单的方法,直到证明它是错误的. /p>

更新2:

我已经创建了一个红宝石模块,该模块可以提取给定的I-Frame信息.使用ffprobe的ts文件,并根据该信息构建I帧和通常的字节范围m3u8播放列表(应要求提供).

我发现创建前面提到的I-Frame播放列表的简单方法不正确,因此我使用了iframe-playlist-generator中的方法.输出几乎与mediafilesegmenter -output-single-file -file-base output-dir/ input.ts生成的I-Frame播放列表相似,由 Duvrai 提及,但有时有些188字节大小的随机帧丢失,我无法理解该模式,因此当前被忽略.

Apple gives an example of support for byte-range segments in m3u8 files for HLS

#EXTM3U
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-VERSION:4
#EXTINF:10.0,
#EXT-X-BYTERANGE:75232@0
media.ts
#EXTINF:10.0,
#EXT-X-BYTERANGE:82112@752321
media.ts 
#EXTINF:10.0, 
#EXT-X-BYTERANGE:69864
media.ts

But I cannot figure out how to create such playlist for given .ts file. Are there any tools for that?

解决方案

Looks like

ffprobe -show_frames media.ts -print_format json

gives enough information about frames to build such playlist, although some scripting will be required to construct it.

I'll update this answer with script if I succeed with that approach.

Update:

Here is couple of useful links I've found by now:

Bash scripts for generating iframe playlists - needs a bit of optimization, as it calls ffprobe multiple times

iframe-playlist-generator - project on python that can be used to generate iframe playlists from usual ones

It is not exactly what I've searched initially, but I-Frame playlists are similar to byte-range ones and fit for my task even better, so I'm going to use these two projects as a reference/starting point to create something a bit more suitable for me.

The projects actually use different methods to find size of I-Frame - the bash script just uses what ffprobe shows in pkt_size, and the python project adds a bit of voodoo by calculating size as difference of positions of packets and adding 188 to match example playlists from apple. 188 bytes is the size of mpeg-ts packet, probably that is related somehow, I have not managed to understand how, however. This difference in size calculation causes different playlists to be generated, probably one of them is incorrect in some way, but actually VLC plays both without any problems, so I'm going to stick to simpler method until it will be proven as incorrect.

Update 2:

I've created a ruby module that can extract I-Frame information of given .ts file with ffprobe and build both I-Frame and usual byterange m3u8 playlist (as it was requested in question) based on that information.

I've found the simple method of creating I-Frame playlist I mentioned before to be incorrect, so I used the method from iframe-playlist-generator. The output is almost similar to the I-Frame playlist generated by mediafilesegmenter -output-single-file -file-base output-dir/ input.ts, mentioned by Duvrai, but sometimes there are some 188-byte size misses for random frames, I could not understand the pattern, so it is currently ignored.

这篇关于如何为HLS创建字节范围的m3u8播放列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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