No EXT-X-MEDIA-SEQUENCE in HLS playlist

627 views
Skip to first unread message

Aleksey Ivanov

unread,
Dec 12, 2017, 12:08:18 PM12/12/17
to Shaka Packager Users
Hello.

I use the packager to generate HLS for live stream.
For test purposes I use FFmpeg to generate a stream.

First I run Shaka in Docker:
packager \
  'input=udp://0.0.0.0:5004,stream=video,init_segment=hls/video_init.mp4,segment_template=hls/video_$Number$.ts,playlist_name=video.m3u8' \
  'input=udp://0.0.0.0:5004,stream=audio,init_segment=hls/audio_init.mp4,segment_template=hls/audio_$Number$.ts,playlist_name=audio.m3u8' \
  --hls_master_playlist_output hls/playlist.m3u8 --hls_playlist_type LIVE


Then I run FFmpeg on host machine:
ffmpeg \
  -f lavfi -re -i "testsrc=duration=-1:size=1280x720:rate=30" \
  -f lavfi -re -i "sine=f=50:beep_factor=6" \
  -pix_fmt yuv420p \
  -c:v libx264 -preset:v ultrafast -profile:v high -level 3.1 -tune:v zerolatency -r 30 -g 60 -sc_threshold 0 \
  -c:a libfdk_aac -preset:a ultrafast \
  -f mpegts udp://$(docker-machine ip default):5004


Unfortunately, when I try to play those files with Shaka Player I got the following error:
Shaka Error MANIFEST.HLS_MEDIA_SEQUENCE_REQUIRED_IN_LIVE_STREAMS ()


As far as I can see from Apple docs (Live Playlist (Sliding Window) section):
For live sessions, the index file is updated by removing media URIs from the file as new media files are created and made available.

My playlists look like this:

hls/playlist.m3u8
#EXTM3U
## Generated with https://github.com/google/shaka-packager version e97c893-release
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="stream_0",URI="audio.m3u8"
#EXT-X-STREAM-INF:BANDWIDTH=532398,CODECS="avc1.42c01f,mp4a.40.2",RESOLUTION=1280x720,AUDIO="audio"
video.m3u8

hls/video.m3u8
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/google/shaka-packager version e97c893-release
#EXT-X-TARGETDURATION:11
#EXT-X-MAP:URI="video_init.mp4"
#EXTINF:10.000,
video_1.ts
#EXTINF:10.000,
video_2.ts
#EXTINF:10.000,
video_3.ts
#EXTINF:10.000,
video_4.ts
#EXTINF:10.000,
video_5.ts
#EXTINF:10.000,
video_6.ts
#EXTINF:10.000,
video_7.ts
#EXTINF:10.000,
video_8.ts
#EXTINF:10.000,
video_9.ts
#EXTINF:10.000,
video_10.ts
#EXTINF:10.000,
video_11.ts
#EXTINF:10.000,
...

I have read from the packager documentation that:
Packager does not support removing old segments internally. The user is responsible for setting up a cron job to do so.

But I think it is related to removing files itself.
As I understand the packager should remove some segments from playlist and increment EXT-X-MEDIA-SEQUENCE tag.
There is a code related to that, but unfortunately I am not able to understand it. In which cases we would get into that else branch?

So, my playlists is just getting longer and there is EXT-X-MEDIA-SEQUENCE tag in there.

Could you please tell me to figure it out?
It there is anything I could do to add EXT-X-MEDIA-SEQUENCE to playlist?
Is it a bug in the packager or it is me missing something?

Thank you.


KongQun Yang

unread,
Dec 12, 2017, 12:26:04 PM12/12/17
to Aleksey Ivanov, Joey Parrish, Shaka Packager Users
Hi Aleksey,

Shaka Packager does generate EXT-X-MEDIA-SEQUENCE, but only when it is not 0: https://github.com/google/shaka-packager/blob/master/packager/hls/base/media_playlist.cc#L91. The tag will be generated when EXT-X-MEDIA-SEQUENCE becomes non-zero, i.e. when playlists update.


   If the Media Playlist file does not contain an EXT-X-MEDIA-SEQUENCE
   tag then the Media Sequence Number of the first Media Segment in the
   Media Playlist SHALL be considered to be 0.  A client MUST NOT assume
   that segments with the same Media Sequence Number in different Media
   Playlists contain matching content - see Section 6.3.2.

+Joey, does Shaka Player require EXT-X-MEDIA-SEQUENCE to be present for live playlist? This does not seem to be correct.


-- KongQun Yang (KQ)

--
You received this message because you are subscribed to the Google Groups "Shaka Packager Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-packager-users+unsub...@googlegroups.com.
To post to this group, send email to shaka-packager-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shaka-packager-users/156a33bc-9b61-455b-95c6-45f23e5cbfe5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aleksey Ivanov

unread,
Dec 12, 2017, 12:56:42 PM12/12/17
to Shaka Packager Users
Thank you KQ,

Yes, I saw the code:
if (media_sequence_number > 0) {
        base::StringAppendF(&header, "#EXT-X-MEDIA-SEQUENCE:%d\n",
                            media_sequence_number);
      }

And it can become non-zero only here.
So, we need num_segments_removed to be greater than zero too.
But how could we achieve that? 
As I wrote above in my case no segments were removed, they were only appended to a playlist.

The specification you linked is related to client-side behaviour, right?

Joey Parrish

unread,
Dec 12, 2017, 1:16:09 PM12/12/17
to KongQun Yang, Aleksey Ivanov, Shaka Packager Users
I suppose that's a player bug.  Please file here: https://github.com/google/shaka-player/issues/new

It should be pretty easy to fix.



-- KongQun Yang (KQ)

To unsubscribe from this group and stop receiving emails from it, send an email to shaka-packager-users+unsubscrib...@googlegroups.com.

KongQun Yang

unread,
Dec 12, 2017, 1:16:24 PM12/12/17
to Aleksey Ivanov, Shaka Packager Users
Hi Aleksey, 

See my replies inline.

-- KongQun Yang (KQ)

On Tue, Dec 12, 2017 at 9:56 AM, Aleksey Ivanov <iale...@gmail.com> wrote:
Thank you KQ,

Yes, I saw the code:
if (media_sequence_number > 0) {
        base::StringAppendF(&header, "#EXT-X-MEDIA-SEQUENCE:%d\n",
                            media_sequence_number);
      }

And it can become non-zero only here.
So, we need num_segments_removed to be greater than zero too.
But how could we achieve that? 

It happens when buffer shifts. The default "--time_shift_buffer_depth" is 30 minutes. You can adjust it, for example, set it to 60, i.e. 60 seconds. You should be able to see the sequence number updated every 60 seconds.
 
As I wrote above in my case no segments were removed, they were only appended to a playlist.

The specification you linked is related to client-side behaviour, right?

Yes. 

--
You received this message because you are subscribed to the Google Groups "Shaka Packager Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-packager-users+unsub...@googlegroups.com.
To post to this group, send email to shaka-packager-users@googlegroups.com.

Aleksey Ivanov

unread,
Dec 12, 2017, 3:19:08 PM12/12/17
to Shaka Packager Users
Thank you KQ, 

I use --time_shift_buffer_depth 60, it does the trick!

It would be nice to document this option for HLS, since now packager --help only prints info about it in "Flags from ../../packager/app/mpd_flags.cc:" section.
What do you think?

Joey, thanks, I will report a bug.

KongQun Yang

unread,
Dec 12, 2017, 5:44:38 PM12/12/17
to Aleksey Ivanov, Shaka Packager Users


-- KongQun Yang (KQ)

On Tue, Dec 12, 2017 at 12:19 PM, Aleksey Ivanov <iale...@gmail.com> wrote:
Thank you KQ, 

I use --time_shift_buffer_depth 60, it does the trick!

It would be nice to document this option for HLS, since now packager --help only prints info about it in "Flags from ../../packager/app/mpd_flags.cc:" section.
What do you think?

Yes, that should be fixed. Filed an issue to track it: https://github.com/google/shaka-packager/issues/304

Joey, thanks, I will report a bug.

--
You received this message because you are subscribed to the Google Groups "Shaka Packager Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shaka-packager-users+unsub...@googlegroups.com.
To post to this group, send email to shaka-packager-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages