如何为HLS创建byte-range m3u8播放列表?

时间:2021-05-07 18:59:32

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

苹果为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

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

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

4 个解决方案

#1


6  

There is -hls_flags as a ffmpeg option. (https://www.ffmpeg.org/ffmpeg-formats.html)

这里有-hls_flags作为ffmpeg选项。(https://www.ffmpeg.org/ffmpeg-formats.html)

Following command generates single ts file which is segmented by byte range feature(supported from HLS version 4) in m3u8 index file.

以下命令生成一个由m3u8索引文件中的字节范围特性(由HLS版本4支持)分割的单个ts文件。

$ ffmpeg -i sample.mp3 -hls_time 20 -hls_flags single_file out.m3u8

#2


4  

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播放列表的Bash脚本——需要进行一些优化,因为它会多次调用ffprobe。

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

iframe-playlist-generator - python项目,它可以用来生成通常的iframe播放列表。

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.

这并不是我最初搜索的内容,但是I- frame播放列表与字节范围的播放列表类似,而且更适合我的任务,所以我将使用这两个项目作为参考/出发点来创建更适合我的东西。

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.

项目实际上使用了不同的方法来查找I-Frame的大小——bash脚本只是使用了ffprobe在pkt_size中显示的内容,而python项目通过计算包位置的不同来增加一些voodoo,并添加了188来匹配来自苹果的示例播放列表。188字节是mpeg-ts包的大小,可能这是相关的,但是我还没有设法理解。这种大小计算上的差异会导致产生不同的播放列表,其中可能有一个是不正确的,但实际上VLC没有任何问题,所以我将坚持更简单的方法,直到它被证明是不正确的。

Update 2:

更新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.

我已经创建了一个ruby模块,它可以通过ffprobe来提取给定的.ts文件的I- frame信息,并基于该信息构建I框架和通常的byterange m3u8播放列表(按照问题的要求)。

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.

我已经找到了创建I- frame播放列表的简单方法,我之前提到过是不正确的,所以我使用了iframe-playlist-generator的方法。输出几乎与mediafilesegmenter -输出-单文件-文件-基础输出-dir/输入生成的I-Frame播放列表相似。ts, Duvrai提到过,但有时会有一些188字节大小的随机帧,我无法理解这个模式,所以它现在被忽略了。

#3


1  

You can use a standard segmenter such as Apple's mediafilesegmenter, check the lengths of the files, and then concatenate (with the cat program) them into a single file. From the file sizes you have all the information needed to specify the byte ranges in a playlist file.

您可以使用标准的segmenter,比如苹果的mediafilesegmenter,检查文件的长度,然后将它们连接到一个文件中。从文件大小中,您拥有在播放列表文件中指定字节范围所需的所有信息。

Not as nice as just downloading a tool from the net, but it's not a very complicated algorithm.

不像从网上下载一个工具那么好,但它不是一个非常复杂的算法。

#4


0  

Unified Streaming also offers a tool that can do this for you:

统一流媒体也提供了一个工具,可以为你做这个:

mp4split --package-hls output-single-file -o prog_index.m3u8 input.mp4

This is part of their commercial streaming package (they offer a free trial upon request). They also provide an Amazon AWS instance with hourly fees.

这是他们的商业流媒体包的一部分(他们提供免费试用)。他们还提供亚马逊AWS实例,每小时收费。

#1


6  

There is -hls_flags as a ffmpeg option. (https://www.ffmpeg.org/ffmpeg-formats.html)

这里有-hls_flags作为ffmpeg选项。(https://www.ffmpeg.org/ffmpeg-formats.html)

Following command generates single ts file which is segmented by byte range feature(supported from HLS version 4) in m3u8 index file.

以下命令生成一个由m3u8索引文件中的字节范围特性(由HLS版本4支持)分割的单个ts文件。

$ ffmpeg -i sample.mp3 -hls_time 20 -hls_flags single_file out.m3u8

#2


4  

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播放列表的Bash脚本——需要进行一些优化,因为它会多次调用ffprobe。

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

iframe-playlist-generator - python项目,它可以用来生成通常的iframe播放列表。

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.

这并不是我最初搜索的内容,但是I- frame播放列表与字节范围的播放列表类似,而且更适合我的任务,所以我将使用这两个项目作为参考/出发点来创建更适合我的东西。

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.

项目实际上使用了不同的方法来查找I-Frame的大小——bash脚本只是使用了ffprobe在pkt_size中显示的内容,而python项目通过计算包位置的不同来增加一些voodoo,并添加了188来匹配来自苹果的示例播放列表。188字节是mpeg-ts包的大小,可能这是相关的,但是我还没有设法理解。这种大小计算上的差异会导致产生不同的播放列表,其中可能有一个是不正确的,但实际上VLC没有任何问题,所以我将坚持更简单的方法,直到它被证明是不正确的。

Update 2:

更新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.

我已经创建了一个ruby模块,它可以通过ffprobe来提取给定的.ts文件的I- frame信息,并基于该信息构建I框架和通常的byterange m3u8播放列表(按照问题的要求)。

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.

我已经找到了创建I- frame播放列表的简单方法,我之前提到过是不正确的,所以我使用了iframe-playlist-generator的方法。输出几乎与mediafilesegmenter -输出-单文件-文件-基础输出-dir/输入生成的I-Frame播放列表相似。ts, Duvrai提到过,但有时会有一些188字节大小的随机帧,我无法理解这个模式,所以它现在被忽略了。

#3


1  

You can use a standard segmenter such as Apple's mediafilesegmenter, check the lengths of the files, and then concatenate (with the cat program) them into a single file. From the file sizes you have all the information needed to specify the byte ranges in a playlist file.

您可以使用标准的segmenter,比如苹果的mediafilesegmenter,检查文件的长度,然后将它们连接到一个文件中。从文件大小中,您拥有在播放列表文件中指定字节范围所需的所有信息。

Not as nice as just downloading a tool from the net, but it's not a very complicated algorithm.

不像从网上下载一个工具那么好,但它不是一个非常复杂的算法。

#4


0  

Unified Streaming also offers a tool that can do this for you:

统一流媒体也提供了一个工具,可以为你做这个:

mp4split --package-hls output-single-file -o prog_index.m3u8 input.mp4

This is part of their commercial streaming package (they offer a free trial upon request). They also provide an Amazon AWS instance with hourly fees.

这是他们的商业流媒体包的一部分(他们提供免费试用)。他们还提供亚马逊AWS实例,每小时收费。