Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop TS file in m3u8 playlist

I want to create m3u8 playlist, like this:

#EXTINF:-1,LIVE STREAM
http://example.com/live01.ts

When this file ended I want repeat in loop. After live01.ts ended, need to start again and do this infinity in loop.

Is this possible?

like image 954
Aleksandar Avatar asked Jan 25 '16 11:01

Aleksandar


2 Answers

It's not possible with a static playlist like that.

First, you'll have to have a #EXT-X-DISCONTINUITY tag before the #EXTINF tag so the player knows the timestamps on the video/audio frames aren't going to continue in order.

Second, and more importantly, you'll need a #EXT-X-MEDIA-SEQUENCE:<number> and/or #EXT-X-DISCONTINUITY-SEQUENCE:<number> at the head of the file that increments at the same rate as the duration of that chunk of video. The player is going to be re-requesting the playlist (until it sees #EXT-X-ENDLIST) and without incrementing those values it will continue to assume that http://example.com/live01.ts is the first chunk in the sequence.

If you're serving the M3U8 file directly and you have a sleep command on your system that supports milliseconds, I'd suggest something like this:

file="/path/to/file.m3u8"
duration="1.337"

make_playlist() {
  echo "#EXTM3U"
  echo "#EXT-X-MEDIA-SEQUENCE:${1}"
  echo "#EXT-X-DISCONTINUITY-SEQUENCE:${1}"
  echo "#EXT-X-DISCONTINUITY"
  echo "#EXTINF:${duration},"
  echo "http://example.com/live01.ts"
  echo
}

for ((x=0;;x++)); do
  make_playlist "${x}" > "${file}"
  sleep "${duration}"
done
like image 69
MithrilTuxedo Avatar answered Nov 15 '22 08:11

MithrilTuxedo


This is not an official feature of m3u8. The looping itself must be done as a player setting.

like image 34
szatmary Avatar answered Nov 15 '22 07:11

szatmary