Syntax
What EXT-X-MEDIA-SEQUENCE means
Every media segment has a media sequence number. EXT-X-MEDIA-SEQUENCE gives the number of the first segment listed in the playlist, and each following segment is one higher. Without the tag, the first segment is number 0.
The value is a decimal integer. Segment file names do not have to contain the number, though they often do.
Where it goes
Media playlists only, once, before the first segment. It matters most in live playlists, where old segments drop off the top as new ones are added at the bottom.
Rules from RFC 8216
Section 4.3.3.2 and sections 6.2.2 and 6.3 set these rules:
- The tag must appear before the first segment.
- If a server removes segments from a playlist, the playlist must contain this tag, and its value must go up by 1 for every segment removed.
- The value must never go down or wrap around.
- Segments must be removed in the order they appear.
- Players must not assume that the same number in two different media playlists, such as the 720p and 480p ones, means the same moment. They must use each segment's position on the timeline and its discontinuity sequence number instead.
- After a reload, players should check that each segment still has the same URI as the segment with the same number in the previous version, and halt playback if not.
Common mistakes
- Starting again at zero when an encoder restarts. Players that track numbers may think nothing new has arrived, or replay old segments.
- Counting wrong. If two segments drop off but the value only goes up by one, every number shifts and players can skip or repeat a segment.
- Leaving it out of a live playlist. Without it, every reload looks as if it starts at segment 0.
How players treat it
To play normally, a player loads next the segment with the lowest number above the last one it loaded, and repeats this after every reload. With AES-128 encryption and no IV attribute, the media sequence number also serves as the initialization vector, so a wrong number makes decryption fail.
Example
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:2681
#EXTINF:6.000,
live/seg2681.ts
#EXTINF:6.000,
live/seg2682.ts
#EXTINF:6.000,
live/seg2683.tsThe first segment listed is number 2681, so the next two are 2682 and 2683; when the oldest segment drops off, the value goes up by one.
How m3u8.cloud handles it
When you record a live stream, m3u8.cloud uses the media sequence number to spot new pieces each time the playlist reloads. The m3u8 inspector also shows the value.
Related tags
Check the tags in any playlist
Open the m3u8 inspector