
An **M3U8 file** is the heart of HLS streaming. While it may look like a random collection of tags and URLs, its structure is strictly defined by the HLS specification. Understanding this structure—which tags are required, how they interact, and how to organize segments—is crucial for anyone working with video streams. This guide breaks down the M3U8 file structure for beginners.
The Two Types of M3U8 Playlists
M3U8 files serve two distinct purposes, resulting in two types of playlists:
- Master Playlist: The entry point. It lists other M3U8 files (Media Playlists) for different quality levels. It enables **Adaptive Bitrate (ABR)** streaming.
- Media Playlist: The segment list. It lists the actual video segments (`.ts` files). The player reads this to fetch the video content.
Essential Tags in a Media Playlist
The Media Playlist is what tells the player *what* to play and *for how long*. Here are the key elements:
| Tag | Description | Example |
|---|---|---|
#EXTM3U |
Mandatory. Identifies the file as an extended M3U format. Must be the first line. | #EXTM3U |
#EXT-X-VERSION |
Indicates the HLS compatibility version (3 or higher). | #EXT-X-VERSION:3 |
#EXT-X-TARGETDURATION |
Specifies the maximum segment duration in the playlist (in seconds). All segments must be equal to or less than this value. | #EXT-X-TARGETDURATION:10 |
#EXTINF |
A required tag preceding each media segment URL. It specifies the duration of the segment. | #EXTINF:9.970, |
| Segment URL | The actual URL (relative or absolute) of the video segment. | video_seg_0.ts |
#EXT-X-ENDLIST |
Indicates that no more segments will be added. Used only for **VOD (Video On Demand)** streams. Live streams omit this tag. | #EXT-X-ENDLIST |
Example of a Basic VOD Media Playlist:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:9.970,
video_seg_0.ts
#EXTINF:10.000,
video_seg_1.ts
#EXT-X-ENDLIST
Tags in a Master Playlist (Adaptive Bitrate)
The Master Playlist's main job is to inform the player about all the available quality options.
| Tag | Description | Example |
|---|---|---|
#EXT-X-STREAM-INF |
Describes a variant stream (a single quality option). The mandatory **BANDWIDTH** attribute is key for ABR. | #EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720 |
| Playlist URL | The URL of the specific Media Playlist for that quality level. | 720p/index.m3u8 |
Example of a Master Playlist:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
high_res.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720
med_res.m3u8
Advanced M3U8 Elements
Encryption and Security
The `#EXT-X-KEY` tag is used to signal encryption (usually AES-128). It contains the URI of the decryption key file:
#EXT-X-KEY:METHOD=AES-128,URI="http://key-server.com/key.bin"
When the player sees this tag, it fetches the key and uses it to decrypt the following segments. See our Encryption Guide for more details.
Live Streaming Tags
For live content, two tags are crucial in the Media Playlist:
- `#EXT-X-MEDIA-SEQUENCE`: Indicates the sequence number of the first segment. This prevents the player from asking for segments that have already been played and discarded.
- Absence of `#EXT-X-ENDLIST`: The lack of this tag tells the player to continuously check the M3U8 URL for newly added segments.
Playlist Validation
Broken playlists cause playback failures. Common mistakes:
Missing #EXTM3U - Must be first line, exactly as shown
Mismatched durations - TARGETDURATION must be >= longest segment
Wrong line endings - Use Unix line endings (\n), not Windows (\r\n)
Bad URLs - Test each segment URL manually
Online validators exist to check syntax. Search "M3U8 validator" to find them.
Editing M3U8 Files
Since they're text files, you can edit with any text editor. Common edits:
Changing segment paths:
# Before
segment0.ts
# After
https://cdn.example.com/segment0.ts
Removing segments:
Delete both the #EXTINF line and following URL line. Adjust TARGETDURATION if needed.
Combining playlists:
Copy segment entries from one playlist to another. Keep only one #EXTM3U header.
Testing Your Playlist
After creating or editing, test it:
With VLC:
vlc your_playlist.m3u8
With FFmpeg:
ffmpeg -i your_playlist.m3u8 -f null -
This validates without creating output. Errors show what's wrong.
With our player:
Upload your playlist to a web server, then load the URL in our M3U8 player.
Common Playlist Patterns
Simple VOD (single quality):
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXTINF:10.0,
seg0.ts
#EXTINF:10.0,
seg1.ts
#EXT-X-ENDLIST
Multi-quality VOD (master + media):
master.m3u8:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=5000000
high.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000
medium.m3u8
Live stream:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:100
#EXTINF:10.0,
live100.ts
#EXTINF:10.0,
live101.ts
#EXTINF:10.0,
live102.ts
File Organization Best Practices
Organize your M3U8 setup logically:
video/
master.m3u8
1080p/
index.m3u8
segment0.ts
segment1.ts
720p/
index.m3u8
segment0.ts
segment1.ts
This structure keeps different quality levels separate and makes management easier.
Automating Playlist Creation
FFmpeg can generate M3U8 files automatically:
ffmpeg -i input.mp4 \
-codec: copy \
-f hls \
-hls_time 10 \
-hls_list_size 0 \
output.m3u8
This segments the video and creates the playlist. Much easier than manual creation.
Debugging Playlist Issues
When playlists don't work:
Check in browser:
Open the M3U8 URL in your browser. You should see text content. If you see binary data or error, the URL is wrong.
Verify MIME type:
Server should send application/vnd.apple.mpegurl or application/x-mpegURL. Check response headers.
Test segments individually:
Copy segment URLs from playlist, try loading them directly. If segments fail, playlist can't work.
Security Considerations
Don't expose sensitive info:
Playlists are plain text. Anyone can read them. Don't put passwords or tokens directly in playlist files.
Use HTTPS:
Serve playlists over HTTPS to prevent tampering in transit.
Token-based access:
For protected content, generate time-limited tokens in segment URLs rather than relying on playlist obscurity.
Converting Other Formats
Have MP4 or other formats? Convert to M3U8 for streaming:
ffmpeg -i video.mp4 \
-c:v libx264 -c:a aac \
-f hls -hls_time 6 \
output.m3u8
Or go the other way - convert M3U8 to MP4 with our converter tool.
Learning Resources
Want to dive deeper?
- Apple's HLS Specification (RFC 8216)
- FFmpeg HLS documentation
- Test with various players to see compatibility
- Experiment with sample playlists
Conclusion
M3U8 files look complex but follow simple rules. Once you understand tags and structure, you can create, edit, and debug playlists confidently.
Start with simple playlists. Add complexity as needed. The format is forgiving - small mistakes usually don't break everything.
Whether you're streaming your own content or troubleshooting playback issues, understanding M3U8 structure gives you power and flexibility.
Back to Blog