How to create byte-range m3u8 playlist for HLS?

前端 未结 4 804
旧巷少年郎
旧巷少年郎 2021-02-01 08:49

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         


        
4条回答
  •  生来不讨喜
    2021-02-01 09:15

    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.

提交回复
热议问题