videoffmpeghttp-live-streamingflowplayerm3u8

Appending .ts video clip to m3u8 HLS stream


I'm trying to concat multiple streams together without the need to re-encode the videos by using an m3u8 manifest.

The start of every video is the same, as is the end, with a short middle section which has over 7000 variations. What I'm wanting to do is create 7000+ m3u8 files, each of which merges the generic intro, the bespoke middle section and the generic end together to form one HLS stream. Is this possible?

Here's the m3u8 file which is generated by ffmpeg:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:12
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:11.520000,
3_1080p_000.ts
#EXTINF:9.600000,
3_1080p_001.ts
#EXTINF:9.600000,
3_1080p_002.ts
#EXTINF:9.600000,
3_1080p_003.ts
#EXTINF:11.520000,
3_1080p_004.ts
#EXTINF:8.440000,
3_1080p_005.ts
#EXT-X-ENDLIST

I tried adding an extra clip in at the end (also at the start) which also has duration 8.440000 seconds as per the following:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:12
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:11.520000,
3_1080p_000.ts
#EXTINF:9.600000,
3_1080p_001.ts
#EXTINF:9.600000,
3_1080p_002.ts
#EXTINF:9.600000,
3_1080p_003.ts
#EXTINF:11.520000,
3_1080p_004.ts
#EXTINF:8.440000,
3_1080p_005.ts
#EXTINF:8.440000,
4_1080p_005.ts
#EXT-X-ENDLIST

When I try run this, flowplayer detects the updated length and the stream plays but when it gets to playing the appended clip, it skips back to the start as though it's stopped. Any help would be massively appreciated, otherwise I'm going to have to render each video out in full and there's 7000+ to do!

The problem stream is available to view here. It ends at 1min exactly instead of going to 1:08.

Thanks in advance.


Solution

  • The issue here likely stems from the fact that 4_1080p_005.ts chunk is not a direct continuation of 3_1080p_005.ts timestamp-wise. The decoder detects that there is a disruption in the stream between those chunks and fails to continue.

    Please take a look at the HTTP Live Streaming specification which takes these situations into account and provides EXT-X-DISCONTINUITY tag for the m3u8 manifest that instructs the decoder that there is such discontinuity https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-23#section-4.3.2.3

    Snippet that is relevant to your situation

    The EXT-X-DISCONTINUITY tag indicates a discontinuity between the Media Segment that follows it and the one that preceded it.

    Its format is:

    #EXT-X-DISCONTINUITY

    The EXT-X-DISCONTINUITY tag MUST be present if there is a change in any of the following characteristics:

    o file format

    o number, type and identifiers of tracks

    o timestamp sequence

    Try to modify your m3u8 manifest and add the tag between those two affected chunks like so:

    #EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-TARGETDURATION:12
    #EXT-X-MEDIA-SEQUENCE:0
    #EXT-X-PLAYLIST-TYPE:VOD
    #EXTINF:11.520000,
    3_1080p_000.ts
    #EXTINF:9.600000,
    3_1080p_001.ts
    #EXTINF:9.600000,
    3_1080p_002.ts
    #EXTINF:9.600000,
    3_1080p_003.ts
    #EXTINF:11.520000,
    3_1080p_004.ts
    #EXTINF:8.440000,
    3_1080p_005.ts
    #EXT-X-DISCONTINUITY
    #EXTINF:8.440000,
    4_1080p_005.ts
    #EXT-X-ENDLIST