Aziz Berkay Yesilyurt

aziz@appvisor.dev

Merging Videos with HLS

HTTP Live Streaming (HLS) playlists allow you to combine video segments into what appears as a single continuous video to viewers. It's a popular technique for streaming live videos on the web, as future video segments can be added to the playlist without interrupting the playback.

You can use this technique to merge multiple videos into a single video. This technique is particularly useful when you need to dynamically modify video content without paying the cost of re-encoding the whole video.

Technical Details

A HLS playlist file looks like this:

        #EXTM3U
#EXTINF:1.000000,
bunny_segment000.ts
#EXTINF:1.000000,
bunny_segment001.ts
#EXT-X-ENDLIST
    

This playlist is composed of 2 video segments called bunny_segment000.ts and bunny_segment001.ts. We can insert new segments to the playlist by adding new lines to the file. These segments can be from different videos. Let's say we want to play one second of a bunny_segment000.ts and then one second of a rick_segment000.ts and finally one second of a bunny_segment001.ts. The playlist for such a case would look like this:

        #EXTM3U
#EXTINF:1.000000,
bunny_segment000.ts

#EXTINF:1.000000,
rick_segment000.ts

#EXTINF:1.000000,
bunny_segment001.ts
#EXT-X-ENDLIST
    

I am omitting some details of the actual playlist file here for brevity. Here is an example video that looks like a single continuous video: