EdgeOne Logo
Tencent EdgeOne Blog
Tech

What is M3U8 and What is M3U Playlist? How to Open and Convert It?

Tencent EdgeOne - Product Manager

m3u8.png

The M3U (Moving Picture Experts Group Audio Layer 3 Uniform Resource Locator) file format is not essentially an audio or video file. It cannot read network resource audio or video in offline mode. It is a playlist file for audio and video files and is a plain text file.

The Unicode version of M3U is M3U8, which uses UTF-8-encoded characters. M3U8 files are the basis for the HTTP Live Streaming (HLS) format originally developed by Apple to stream video and radio to iOS devices, and which is now a popular format for adaptive streaming in general.

The specific calculations and explanations are detailed in the M3U8 section of the English version of Wikipedia. As we can see, the m3u8 file is actually a part of the HTTP Live Streaming (HLS) protocol.

What is HLS?

3e0d1307-5562-4b3b-b40a-a42e758df210.png

HLS is a media streaming protocol based on HTTP developed by Apple Inc. It was primarily designed to address the issues of transmitting and playing online video streams.

Compared to traditional streaming media technologies such as RTSP protocol (there are three types of streaming media protocols: RTMP, RTSP, and HTTP Live Streaming), HLS has the advantage that once the segmentation is completed, no additional specialized software is required for distribution, and a regular web server can be used, which reduces the technical requirements for servers. For widely used CDN services, it greatly reduces the configuration requirements of CDN edge servers and can use any existing CDN.

For non-real-time video, if you want to jump in a long video using a single MP4 format video file and the HTTP protocol, you need a proxy server that supports HTTP range requests to obtain a part of the large file. Not all proxy servers support this well. HTTP Live Streaming only needs to download the corresponding TS segment based on the timeline in the m3u playlist file, without HTTP range requests, which requires less of a proxy server because all proxy servers support efficient caching of small files.

In addition, using TS for streaming media packaging has another advantage, which is that there is no need to load the index before playing, greatly reducing the initial loading delay and improving the user experience.

Furthermore, the biggest advantage of HTTP Live Streaming is adaptive bitrate streaming. The client automatically selects video streams of different bitrates based on the network conditions, using high bitrates when conditions permit and low bitrates when the network is busy, and automatically switches between the two. This is very helpful for ensuring smooth playback in unstable mobile device network conditions.

What is M3U8 and M3U Playlist?

The m3u8 file is essentially a m3u playlist, which can be a media playlist or a master playlist. However, regardless of the type of playlist, the text used inside is encoded in utf-8.

When the m3u8 file is used as a media playlist, it records a series of media segment resources that can be played in sequence to display the complete multimedia resource. Its format is as follows:

#EXTM3U
#EXT-X-TARGETDURATION:10

#EXTINF:9.009,
http://media.example.com/first.ts
#EXTINF:9.009,
http://media.example.com/second.ts
#EXTINF:3.003,
http://media.example.com/third.ts

For on-demand playback, the client only needs to download the segment resources in order and play them one by one. However, for live streaming, the client needs to periodically request the m3u8 file to check if there are new segment data that needs to be downloaded and played.

When the m3u8 file is used as a master playlist, it provides a list of variant streams for the same media resource. Its format is as follows:

#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/low/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=240000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/lo_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=440000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/hi_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=640000,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/high/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5"
http://example.com/audio/index.m3u8

The variant stream resources specify multiple media playlists with different bitrates and formats. Additionally, the variant stream resources can also provide different versions of the content, such as audio files in different languages or video files shot from different angles. Clients can select the appropriate bitrate resources based on different network conditions, and it is recommended to select the appropriate content based on user preferences.

To learn more about m3u playlist and the HLS protocol, you can refer to the following links:

HLS.js Documentation

Creating a Master Playlist

Adding Alternate Media to a Playlist

M3U8 File Format

The m3u8 file format mainly includes three aspects:

M3U Playlist

The content of the m3u playlist (m3u8 file) must strictly comply with the requirements of the defined specification. The following are some of the main conditions that need to be followed: 

  • The m3u8 file must be encoded in utf-8 and cannot use Byte Order Mark (BOM) byte order. It cannot contain utf-8 control characters (U+0000 ~ U_001F and U+007F ~ u+009F). 
  • Each line of the m3u8 file must be either a URI, an empty line, or a string starting with #. No white space characters are allowed except for explicitly declared elements. 
  • Strings starting with # in the m3u8 file are either comments or tags. Tags start with #EXT and are case sensitive.

Attribute Lists

Some specific tags have values in the form of attribute lists. The attribute list following the tag is separated into multiple sets of attribute/value pairs without spaces, using a comma as the separator.

The syntax format of the attribute/value pair is as follows:

AttributeName=AttributeValue

The AttributeName is an unquoted string composed of [A..Z], [0..9], and -. Therefore, AttributeName can only use uppercase letters and cannot use lowercase letters. There should be no spaces between AttributeName and =, and similarly, there should be no spaces between = and AttributeValue.

Tags

Tags are used to specify global parameters of the m3u8 file or some information about the segment files/media playlists that follow it.

Tags can be divided into five types: Basic Tags, Media Segment Tags, Media Playlist Tags, Master Playlist Tags, and Playlist Tags. Their specific contents are shown below:

  1. Basic Tags:
  • #EXTM3U
  • #EXT-X-VERSION
  • #EXT-X-ALLOW-CACHE
  • #EXT-X-MEDIA-SEQUENCE
  • #EXT-X-TARGETDURATION
  1. Media Segment Tags:
  • #EXTINF
  • #EXT-X-BYTERANGE
  • #EXT-X-DISCONTINUITY
  • #EXT-X-KEY
  • #EXT-X-MAP
  • #EXT-X-PROGRAM-DATE-TIME
  • #EXT-X-DATERANGE
  1. Media Playlist Tags:
  • #EXT-X-TITLE
  • #EXT-X-PLAYLIST-TYPE
  • #EXT-X-MEDIA
  • #EXT-X-STREAM-INF
  • #EXT-X-I-FRAME-STREAM-INF
  • #EXT-X-ENDLIST
  1. Master Playlist Tags:
  • #EXT-X-MEDIA
  • #EXT-X-STREAM-INF
  • #EXT-X-I-FRAME-STREAM-INF
  • #EXT-X-SESSION-DATA
  • #EXT-X-SESSION-KEY
  1. Playlist Tags:
  • #EXT-X-DISCONTINUITY-SEQUENCE
  • #EXT-X-ENDLIST
  • #EXT-X-INDEPENDENT-SEGMENTS
  • #EXT-X-START
  • #EXT-X-VERSION

How to Open M3U8 Files?

M3U8 files are playlists containing references to media files. They can be opened and played using media players that support the M3U8 format. Here are the steps to open M3U8 files:

  • VLC media player
  • Windows Media Player
  • QuickTime Player
  • KMPlayer
  • RealNetworks RealPlayer

M3U8 files are typically used for streaming media content over the internet. The media files referenced in the playlist may not be stored locally on your computer, but rather on a remote server. Therefore, a stable internet connection is required to play the media files smoothly.

How to covert M3U8 to Mp4?

M3U8 files are playlists containing references to media files, while MP4 is a video file format. To convert M3U8 to MP4, you need to download the media files referenced in the playlist and then use a video converter to convert them to MP4 format. 

1. Download the media files referenced in the M3U8 playlist. You can use a video downloader tool such as Video DownloadHelper, VLC media player, or IDM (Internet Download Manager) to download the media files.

2. Once the media files are downloaded, use a video converter tool to convert them to MP4 format. There are many video converter tools available online, such as HandBrake, Any Video Converter, and Freemake Video Converter.

3. Open the video converter tool and select the media files you want to convert. Choose the MP4 format as the output format.

4. Customize the video settings such as resolution, bitrate, and frame rate if necessary.

5. Start the conversion process and wait for it to complete.

6. Once the conversion is complete, you will have an MP4 video file that you can play on any media player that supports MP4 format.

Converting M3U8 to MP4 may result in loss of quality, depending on the video converter tool and settings used.

Tencent Edge Function

Tencent Edge Function provides a serverless code execution environment for the edge nodes of Tencent EdgeOne. Thanks to the programmable capabilities of EdgeOne edge functions, developers can process M3U8 media files at edge nodes and dynamically modify and inject content. Here are some common scenarios:

  1. Customized playlist: Developers may need to choose different media streams based on users' network conditions, device performance, or geographic location.
  2. Content security and access control: To protect copyrighted content, developers may need to process M3U8 files to implement encryption, add access tokens, and other features.
  3. Ad insertion: Inserting ads in streaming media content is a common business model. Developers can modify M3U8 files to insert ad segments at specific times during video playback.

Rewriting and processing M3U8 files can help developers achieve richer and more flexible streaming media application scenarios. You are welcome to Contact Us for more information.

Develop
Edge Function
Web