What is a M3U8 file?

M3U8 files

This article explains what an M3U8 file is used for, which is the file structure, why is used in HLS and which programs are able to use it to play media files, and how to convert one to a different format (mp4) using FFmpeg.

If you find it challenging to track down your favorite media files, this guide will provide you with deeper insights. Keep reading:

TABLE OF CONTENTS:

Understanding M3U8 Files
Opening and Viewing M3U8 Files
Converting M3U8 to Different Formats
Concluding Remarks

Understanding M3U8 Files

M3U8 files are playlists used by various video and audio players to organize and access media files. They consist of plain text, which facilitates users in quickly playing media content. These files may reference media using URLs or absolute file paths, and can also include information on media from internet radio stations. Popular players such as iTunes, VLC Media Player, and Windows Media Player support M3U8 files. Plain text editors like Microsoft Notepad and Apple TextEdit can also open these files.

Example of M3U8 File

This code is an example of a Video on Demand playlist:

#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
http://example.com/stream1/fileSeqA.ts
#EXTINF:10.0,
http://example.com/stream1/fileSeqB.ts
#EXTINF:10.0,
http://example.com/stream1/fileSeqC.ts
#EXTINF:9.0,
http://example.com/stream1/fileSeqD.ts
#EXT-X-ENDLIST

The following sketch explains the content of the M3U8 file:

M3U8 files

What is the correct MIME type for M3U8 files?

The correct MIME type for M3U8 files is application/vnd.apple.mpegurl.

Different MIME types for a HLS playlist

File ExtensionMIME Type
.m3u8application/vnd.apple.mpegurl
.tsvideo/MP2T
.mp4video/mp4

Different Types of M3U8 Playlists

M3U8 playlists are designed to accommodate a variety of streaming experiences. Here's a breakdown of the various playlist categories:

  • Video on Demand (VOD): VOD playlists are static, containing URLs for all media segments from the outset. This allows for full and immediate access to the content.
  • Event: Event playlists expand as new content is incorporated. Recognized by the EXT-X-PLAYLIST-TYPE tag set to EVENT, they lack the EXT-X-ENDLIST tag, indicating that content will continue to be added.
  • Live: Live streaming playlists are updated in real-time, with older media URIs being phased out for newer ones. The ongoing nature of the stream is signaled by not having the EXT-X-ENDLIST tag.
  • Multivariant: Multivariant playlists detail all available stream quality options, each with its own playlist. This allows clients to adaptively switch between streams based on network performance, ensuring a buffer-free streaming experience. For additional details, see Creating a Multivariant Playlist article on Apple developer website.

Opening and Viewing M3U8 Files

To open M3U8 files, a simple text editor is sufficient. On Windows, Notepad is capable of displaying the contents of M3U8 files. However, to play the media listed within, a dedicated media player is necessary. Here's a selection of media players across Windows, Mac, and Linux that can handle M3U8 files effectively.

Windows:

  • VLC Media Player- A highly versatile media player that supports various audio and video formats, including M3U8 playlists.
  • Vidmore Player- A robust media player offering smooth playback for both common and specialized media file types.
  • KMPlayer- A media player with a wide range of codec support and user-friendly features for an enhanced viewing experience.
  • Windows Media Player- Microsoft's own media player, known for its simplicity and compatibility with Windows operating systems.
  • MediaMonkey- A digital media player and media library application that allows for organizing and playing audio on Windows platforms.

Mac:

  • Apple iTunes- A media player and library application that offers a broad range of options for managing and playing audio and video files.
  • RealPlayer- A cross-platform media player app that plays various multimedia formats as well as streaming audio and video.
  • Vidmore Player- A versatile media player that supports playback of common audio and video files, as well as Blu-ray and DVD playback.
  • VLC Media Player- A free and open-source portable cross-platform media player software and streaming media server.
  • Clementine- A modern music player and library organizer focusing on a fast and easy-to-use interface for searching and playing your music.

Linux:

  • VLC Media Player - A free and open-source multimedia player that can handle a wide array of audio and video formats.
  • MPV - A free, open-source, and cross-platform media player known for its minimalistic design and high-quality video output.
  • SMPlayer - A versatile media player with built-in codecs that can play virtually all video and audio formats.

How to Open an M3U8 File with VLC Media Player

Opening an M3U8 file with VLC Media Player is a straightforward process. Follow these simple steps to start streaming your media content.

Step 1: Launch VLC media player. Once open, navigate to the menu and select "Media" followed by "Open File." This will prompt a file browser window to open.

Step 2: Within the file browser, you may need to filter the displayed files. To do this, set the "File Type" dropdown menu to "Playlist Files." This will make it easier to find your M3U8 file. Browse to the location where your M3U8 file is saved, select it, and click "Open" to load the file into VLC. The media content should start playing automatically.

By following these steps, you can easily access your streaming media using VLC, one of the most versatile and user-friendly media players available.

Opening an M3U8 File in a Web Browser

To open an M3U8 file in a web browser, follow these steps:

First, create an HTML page that incorporates the HTML5 <video> element. Use the M3U8 playlist file as the source for the video. For browsers that do not support the HTML5 <video> element or HLS, add a fallback within the <video> tags. This could be a direct download link to a video file or an RTSP stream requiring the QuickTime plugin. Refer to the Safari HTML5 Audio and Video Guide for examples.

Below is the HTML markup for a simple page that plays an HLS stream:

<html>
    <head>
      <title>HTTP Live Streaming Example</title>
    </head>
    <body>
      <video src="http://example.com/stream/index.m3u8" height="300" width="400"></video>
    </body>
  </html>

Opening an M3U8 File (HLS) on Android

To open an M3U8 file in a web browser on an Android device, you can follow similar steps as for desktop browsers:

For native Android apps, you can use libraries such as ExoPlayer to play HLS streams. ExoPlayer supports M3U8 files out of the box and provides extensive customization options. To include ExoPlayer in your Android project, add the following dependencies to your build.gradle file:

dependencies {
    implementation 'com.google.android.exoplayer:exoplayer-core:2.X.X'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.X.X'
    // Other ExoPlayer modules can be added as needed.
}

Then, you can create a player instance and set it up to play an M3U8 file:

// Create a player instance.
SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();

// Prepare the player with the source.
Uri uri = Uri.parse("http://example.com/stream/index.m3u8");
MediaItem mediaItem = MediaItem.fromUri(uri);
player.setMediaItem(mediaItem);
player.prepare();

// Set the player to a view.
PlayerView playerView = findViewById(R.id.player_view);
playerView.setPlayer(player);

// Start the playback.
player.play();

Make sure to replace the 2.X.X with the actual version numbers of ExoPlayer and the URI with the actual path to your M3U8 file. Also, ensure that the player view (PlayerView) is defined in your layout XML.

Converting M3U8 to Different Formats

You might need to convert M3U8 files to formats like MP4, but since M3U8s are plain text files that act as playlists, direct conversion of the file itself is not possible. Instead, what's needed is a process that reads the M3U8 file and then downloads and converts the media files it references into your desired format. A command-line tool like FFmpeg can handle this process by fetching all the media segments referenced in the M3U8 file and merging them into a single video file.

How to Convert an M3U8 Playlist Using FFmpeg

To convert an M3U8 playlist to MP4 using FFmpeg, follow these steps:

  1. Open a Command Prompt or Terminal window. You'll be entering the conversion command here.
  2. Use the FFmpeg command to start the conversion. Enter the following command:
    ffmpeg -i input.m3u8 -c copy -bsf:a aac_adtstoasc output.mp4
    Here's what each part does:
    • ffmpeg: This calls the FFmpeg tool.
    • -i input.m3u8: This specifies the input file, which is your M3U8 playlist.
    • -c copy: This tells FFmpeg to copy the codecs directly without re-encoding the audio and video streams.
    • -bsf:a aac_adtstoasc: This applies a bitstream filter for audio to convert ADTS to ASC. It's necessary when the audio format is AAC and you're copying the codec.
    • output.mp4: This specifies the name of the output file, which will be in MP4 format.
  3. Execute the command. Press Enter to run the command and start the conversion process. FFmpeg will read the M3U8 file, download the media segments, and merge them into a single MP4 file.

Concluding Remarks

M3U8 files maintain playlist data integrity in simple text form, facilitating media discovery and streaming through supported players. The significance and functionality of M3U8 files are concisely discussed in this piece. For efficient M3U8 file conversion, tools such as FFMPEG are recommended.