If you are a music lover and also a technology savvy person, you might be familiar with the M3U8 file extension. However, most people don't understand this format or haven't even heard of it. In fact, M3U8 is widely used on computers, websites and streaming services.
This post will share the basic knowledge about this audio format in detail. Then you will understand what M3U8 is and how to listen to it with the best M3U8 players on Windows 10/8.1/8/7 and Mac OS X/11/12.
M3U8 players
- Part 1: What is m3u8?
- Part 2: Top 5 M3U8 Players
- Part 3: Top 3 m3u8 players online
- Part 4. Frequently asked questions about M3U8 player
Analysis
The first thing that came to my mind was to record a video from the screen, for example via QuickTime, but in this case you need to watch them all and this takes quite a long time and I didn’t like this option.
The next step was to explore the html code of the page, and there I found an interesting link:
Next, I tried to insert this link into the address bar of the browser and as a result, the file master.m3u8 was downloaded with the following content:
#EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=768000,CODECS=»mp4a.40.2, avc1.640028″,RESOLUTION=640×360 https://vh-04.getcourse.ru/player/89cc32eeb182080b719abfc7f106aaaf/5b7008 b4e8fab9852419a5c00e4aa618/ media/360.m3u8?sid=sid&host=vh-04&cdn=1&cdn-second=0&integros-s3=1&akamai-defence=0&v=2:0:1:1 #EXT-X-STREAM-INF:BANDWIDTH=1024000,CODECS= »mp4a.40.2, avc1.640028″,RESOLUTION=853×480 https://vh-04.getcourse.ru/player/89cc32eeb182080b719abfc7f106aaaf/5b7008b4e8fab9852419a5c00e4aa618/media/480.m3 u8?sid=sid&host=vh-04&cdn=1&cdn-second =0&integros-s3=1&akamai-defence=0&v=2:0:1:1 #EXT-X-STREAM-INF:BANDWIDTH=2560000,CODECS=»mp4a.40.2, avc1.640028″,RESOLUTION=1280×720 https: //vh-04.getcourse.ru/player/89cc32eeb182080b719abfc7f106aaaf/5b7008b4e8fab9852419a5c00e4aa618/media/720.m3u8?sid=sid&host=vh-04&cdn=1&cdn-second=0&integros-s3=1& akamai-defence=0&v=2:0:1: 1 #EXT-X-STREAM-INF:BANDWIDTH=4096000,CODECS=»mp4a.40.2, avc1.640028″,RESOLUTION=1920×1080 https://vh-04.getcourse.ru/player/89cc32eeb182080b719abfc7f106aaaf/5b7008 b4e8fab9852419a5c00e4aa618/media /1080.m3u8?sid=sid&host=vh-04&cdn=1&cdn-second=0&integros-s3=1&akamai-defence=0&v=2:0:1:1
As you can see, this file also contains a set of links, and judging by their name, they indicate the resolution of the video that is being loaded.
I decided to see what the 720.m3u8 file was, to do this I downloaded it by following the appropriate link:
#EXTM3U #EXT-X-TARGETDURATION:11 #EXT-X-ALLOW-CACHE:YES #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-PLAYLIST-TYPE:VOD #EXTINF :9.160000, https://getcourse-cdn-a1a5df3e.cdn.integros.com/ch/89cc32eeb182080b719abfc7f106aaaf/5b7008b4e8fab9852419a5c00e4aa618/720/0.ts?sid=sid&host=vh-04 #EXTINF:10.080000, https://getcourse-cdn -a1a5df3e.cdn.integros.com/ch/89cc32eeb182080b719abfc7f106aaaf/5b7008b4e8fab9852419a5c00e4aa618/720/1.ts?sid=sid&host=vh-04 #EXTINF:10.080000, https://getcourse -cdn-a1a5df3e.cdn.integros.com/ch /89cc32eeb182080b719abfc7f106aaaf/5b7008b4e8fab9852419a5c00e4aa618/720/2.ts?sid=sid&host=vh-04 #EXTINF:10.080000, … #EXTINF:8.800000, https://getcourse-cdn-a 1a5df3e.cdn.integros.com/ch/89cc32eeb182080b719abfc7f106aaaf/5b7008b4e8fab9852419a5c00e4aa618 /720/119.ts?sid=sid&host=vh-04 #EXT-X-ENDLIST
If you look closely, you can see that all the links contain *.ts, after I downloaded them, it turned out that these are just pieces of this lesson.
After a little searching about what an m3u8 file is, I found out that it is a format for storing playlists.
Now the question was how to save it locally.
Bonus: Best Media Player for High Quality Video Playback
If you want to play Blu-ray/DVD movies, you can give Blu-ray Master Free Blu-ray Player a try. With this software, you watch videos in popular formats including MP4, AVI, WMV, MTS, TS, FLV, MTS, M2TS, WKV, TRP, MXF, MPEG, etc. with original quality.
- 1. Play many video formats and Blu-ray/DVD movies without losing quality.
- 2. Additional audio tracks/subtitles and custom video effects.
- 3. Provide full, half, normal and many other playback modes.
- 4. Take pictures of your favorite scene while playing a video.
- 5. Offer a user-friendly interface that is easy to navigate.
Wonderful
Rating: 4.8 / 5 (179 votes)
Alternative save
After I saved a couple of videos this way, I began to think about how to optimize the process. Then the thought occurred to me that I could just try to download all these small files and combine them into one.
To do this, I wrote a small utility in Go to process the *.m3u8 file and combine all the small pieces from it into one file.
Its operating algorithm is quite simple: first I follow the given link to m3u8, then I go around it line by line and if the line contains the URL of the piece, I download it and immediately write the result to the output file.
The code that does this is the following:
// received file from server resp, err := http.Get(inputUrl) if err != nil { log.Fatal("Download error: ", err) } defer resp.Body.Close() // create output file f , err := os.Create(outputFile) if err != nil { log.Fatal("Download error: ", err) } defer f.Close() // read server response line by line scanner := bufio.NewScanner( resp.Body) i := 0 for scanner.Scan() { l := scanner.Text() // if line contains url address if strings.HasPrefix(l, "http") { // download file part part, err := downloadFilePart(l) if err != nil { log.Fatal("Download part error: ", err) } // write part to output file if _, err = f.Write(part); err != nil { log.Fatal("Write part to output file: ", err) } log.Printf("Download part %d\n", i) i++ } } if err := scanner.Err(); err != nil { log.Fatal(err) }
The downloadFilePart function is responsible for downloading a file and outputting it to a byte array:
func downloadFilePart(url string) ([]byte, error) { result := make([]byte, 0) resp, err := http.Get(url) if err != nil { return result, err } if result, err = ioutil.ReadAll(resp.Body); err != nil { return result, err } return result, err }
This method completely justified itself and turned out to be the fastest.
How to create an M3U playlist yourself
In addition to classic text editors, to create a playlist in M3U format, you can use special IPTV players that have the function of creating playlists. This is much better than creating them manually. One such player is Simple TV. After installing the program, open it and go to the “Playlist” section, select “Search for channels” from the pop-up list. Set the range of addresses to scan. At the end of the scan, a list of TV channels will open. Check the boxes next to the ones you want to add and click on “Save”.
What do you use the M3U format with?
This article is intended to tell in detail about the intricacies of the M3U playlist format - the de facto standard for many music players, both software and hardware.
A little bit of history
This format appeared in 1997; it was a standard type of playlist for the Winamp program.
This format could not be called anything special - its first version was simply a list of paths to music files, and both relative and full paths were supported. A little later it became possible to use a URL to set the path to a file. The separator was carriage return and line feed (/r/n). Windows-1252 was also used as the standard encoding. Single-line comments of the form # Some comment were also supported. No headers were required to declare that this was an M3U file, or any others. Such ascetic playlists are still used today - for example, they can be used to exchange links to streaming video or audio. The entire playlist will consist of one line:
https://example.com:8000/audio
However, there is an important nuance that has been going on since then to this day - the symbols /r/n must also appear at the end of the last line.
But everything flows and changes. It became clear that file paths alone could not satisfy the needs of both the user and the developer. Increasingly, some players used comments to store their service information - in particular the name of the track and its length. And all this resulted in the next stage in the evolution of the M3U format.
Extended M3U
The extended syntax of the M3U format allows you to set tags for the file, duration and playlist name.
Not much, but nothing more is needed. Additionally, ExtM3U is backward compatible with M3U because it uses comments for markup. However, the requirements for the encoding (and it must be Windows-1252) and for the separator (line feed only with carriage return) remain the same. But relaxations began to appear for the encoding - with the Russian localization selected, many players began to read the playlist in Win-1251. So, let's look at the ExtM3U syntax as an example.
#EXTM3U #PLAYLIST:Playlist Name #EXTINF:100,Track Title music/Track01.mp3 #EXTINF:456,Artist Name — Track Name C:/music/Track01.mp3 #EXTINF:456,Unix Full Pathname /home/usr/ data/music/Track01.mp3 #EXTINF:-1,Some Radiostation https://example.com:8000/radio
- #EXTM3U - M3U file header. This indicates that this is indeed an M3U playlist and that the syntactic structures of the ExtM3U format are fully supported.
In fact, as always, not everything is so rosy. For example, the MP3 player in the Siemens CX75 phone writes this directive at the beginning of the playlist when it is created. But it ignores the rest of the ExtM3U markup. It even refused to digest relative file paths(!).
- #PLAYLIST — playlist name. For example: “Songs about birds.” Not included in the official specification and is an amateur activity of some players.
- #EXTINF - description of the track itself. Let's look at the syntax of this directive in a little more detail.
EXTINF directive
Syntax:
#EXTINF:track_length sec,track_name\r\n path_to_file.ext According to M3U syntax, all directive parameters are described after a colon and separated by commas.
- Duration of the track in seconds. Any positive number, including zero. -1 means ignore track length.
Some players immediately put question marks instead of duration, some still try to determine it themselves. If successful, the track length will be displayed.
- Name of the track. Any phrase in Windows encoding.
If the track has an artist and a title, then it is advisable to use a hyphen (minus) - “-“ as a separator.
- The path to the file. Required parameter, separated from the description of the \r\n directive.
If you specify a relative path, the player will search for files based on the folder where the playlist is located. When specifying a URL, you can specify any protocol that the player supports connection to (http(s), ftp, etc). It is advisable to use http or a special protocol for streaming audio/video rtsp.
But the most important pitfall is encoding. Sometimes, to indicate that Russian letters follow in the name of a track or path, the US symbol is used. But utf-8 suggests itself here. So, the next evolution of M3U playlists is the M3U8 format.
M3U8 - m3u to utf-8
The *.m3u8 format is predominantly used on Unix systems. Many players automatically recognize the file encoding and do not require the presence of eight in the extension. The differences from the regular m3u format are, of course, the utf-8 encoding and the ability to use only line feed (\n) as a line separator.
Conclusion
M3U is a simple and promising playlist format with a thirteen-year history. It is simpler and more understandable than playlists with an xml structure, since csv-like formats for storing small structured amounts of data are much more convenient. Many equipment manufacturers prefer m3u, and this format is supported by all music players. I hope that learning more about these formats will be of benefit to you in the future.
Literature
- m3u format specification (English)
- M3U - Wikipedia (Russian)
PS All links in code tags should be read with protocol designations preceding them. I don’t know how to make Habr leave https:// in links; It’s very strange that in code tags it processes links at all.