knowledge/technology/files/media/m3u.md

11 KiB
Raw Blame History

obj wiki extension mime rev
format https://en.wikipedia.org/wiki/M3U
m3u
m3u8
audio/x-mpegurl 2024-03-07

m3u Playlist

M3U is a computer file format for a multimedia playlist. One common use of the M3U file format is creating a single-entry playlist file pointing to a stream on the Internet. The created file provides easy access to that stream and is often used in downloads from a website, for emailing, and for listening to Internet radio.

Although originally designed for audio files, such as MP3, it is commonly used to point media players to audio and video sources, including online sources. M3U was originally developed by Fraunhofer for use with their Winplay3 software, but numerous media players and software applications now support the format.

Format

There is no formal specification for the M3U format; it is a de facto standard.

An M3U file is a plain text file that specifies the locations of one or more media files. The file is saved with the "m3u" filename extension if the text is encoded in the local system's default non-Unicode encoding, or with the "m3u8" extension if the text is UTF-8 encoded.

Each entry carries one specification. The specification can be any one of the following:

  • an absolute local pathname; e.g., /My Music/Heavysets.mp3
  • a local pathname relative to the M3U file location; e.g. Heavysets.mp3
  • a URL

Each entry ends with a line break which separates it from the following one.

Extended

The M3U file can also include comments, prefaced by the # character. In extended M3U, # also introduces extended M3U directives which are terminated by a colon : if they support parameters.

M3U extensions:

Directive Description Example
#EXTM3U file header, must be the first line of the file #EXTM3U
#EXTINF: track information: runtime in seconds and display title of the following resource
additional properties as key-value pairs
#EXTINF:123,Artist Name Track Title
#EXTINF:123 logo="cover.jpg",Track Title
#PLAYLIST: playlist display title #PLAYLIST:Music TV
#EXTGRP: begin named grouping #EXTGRP:Foreign Channels
#EXTALB: album information, title in particular #EXTALB:Album Title (2009)
#EXTART: album artist #EXTART:Various
#EXTGENRE: album genre #EXTGENRE:Jazz Fusion
#EXTM3A playlist for tracks or chapters of an album in a single file #EXTM3A
#EXTBYT: file size in bytes #EXTBYT:34124
#EXTBIN: binary data follows, usually concatenated MP3s #EXTBIN:
#EXTENC: text encoding, must be the second line of the file #EXTENC:UTF-8
#EXTIMG: cover, logo or other image #EXTIMG:cover.jpg

Apple used the extended M3U format as a base for their HTTP Live Streaming (HLS) which was documented in an Independent Submission Stream RFC in 2017 as RFC 8216. Therein, a master playlist references segment playlists which usually contain URLs for short parts of the media stream. Some tags only apply to the former type and some only to the latter type of playlist, but they all begin with #EXT-X-.

HLS M3U extensions:

Directive Example Description
#EXT-X-START: TIME-OFFSET=0
#EXT-X-INDEPENDENT-SEGMENTS Toggle without parameters
#EXT-X-PLAYLIST-TYPE: VOD or EVENT
#EXT-X-TARGETDURATION: 10 The maximum Media Segment duration in seconds
#EXT-X-VERSION: 4
#EXT-X-MEDIA-SEQUENCE: 0 The Media Sequence Number of the first Media Segment appearing in the playlist file
#EXT-X-MEDIA: NAME="English", TYPE=AUDIO, GROUP-ID="audio-stereo-64", LANGUAGE="en", DEFAULT=YES, AUTOSELECT=YES, URI="english.m3u8"
#EXT-X-STREAM-INF: BANDWIDTH=1123000, CODECS="avc1.64001f,mp4a.40.2 Parameters have either one combined value or one per stream, separated by commas
#EXT-X-BYTERANGE: 1024@256000
#EXT-X-DISCONTINUITY toggle without parameters The segment represents the start of a new period
#EXT-X-DISCONTINUITY-SEQUENCE: 2 Indicates start of numbering of periods
#EXT-X-GAP toggle without parameters The segment represents a "spacer" before a new period
#EXT-X-KEY: METHOD=NONE Indicates encryption method used and decryption key
#EXT-X-MAP: URI=MediaInitializationSection
#EXT-X-PROGRAM-DATE-TIME: 2010-02-19T14:54:23.031+08:00 ISO 8601 format
#EXT-X-DATERANGE: ID=foo
#EXT-X-I-FRAMES-ONLY i-frame Toggle without parameters
#EXT-X-SESSION-DATA: DATA-ID=com.example.movie.title
#EXT-X-SESSION-KEY:
#EXT-X-ENDLIST End-of-list signal without parameters

M3U8

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 2015 proposal for the HLS playlist format uses UTF-8 exclusively and does not distinguish between the "m3u" and "m3u8" file name extensions.

Examples

#EXTM3U
 
#EXTINF:123, Sample artist - Sample title
C:\Documents and Settings\I\My Music\Sample.mp3
 
#EXTINF:321,Example Artist - Example title
C:\Documents and Settings\I\My Music\Greatest Hits\Example.ogg