Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create m3u8 file from list of ts files

I want to create 'm3u8' file from the list of ts files. How can I do it?

I did search in google & read documentation of ffmpeg but I didn't find anything.

like image 650
Mohammad Hossein Gerami Avatar asked Aug 28 '18 08:08

Mohammad Hossein Gerami


People also ask

How do I create a M3U8 file?

Go to “File” tab at the upper-left side, click on it and select “Save as”. Rename your file to an identifiable name and change the file extension right after from “. txt” to “. m3u8”.

What is TS file in M3U8?

ts files. For each output level you need a playlist manifest (m3u8) that contains the list of segment files making up the content. For the whole stream you need a single master manifest (another m3u8) that lists the playlists.

What is the difference between M3U and M3U8?

M3U8 file is a multimedia file format that uses UTF-8 encoded characters. M3U8 file is based on HTTP Live Streaming format. While the M3U file format and M3U are similar file formats. M3U file also uses UTF-8 encoded characters, and uses other encoded characters.

What is the format of an M3U8 file?

A file with the M3U8 file extension is a UTF-8 Encoded Audio Playlist file. They are plain text files that can be used by both audio and video players to describe where media files are located. For example, one M3U8 file may give you references to online files for an internet radio station.


2 Answers

You probably want a HLS structure. There's a lot of documentation at Apple (IIRC it was invented by Apple and then got adopted widely), e.g. a draft RFC and a page with example streams.

HLS consists of two levels: a master M3U8 which references other M3U8 which in turn reference the .ts files. You can omit the master M3U8 and just provide the "second level".

As a starting point, it may look something like this:

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10, no desc
media-000001.ts
#EXTINF:10, no desc
media-000002.ts
#EXTINF:10, no desc
media-000003.ts

The EXT-X-TARGETDURATION specifies how long each .ts file is (they must all be of the same length). It may either be a relative or absolute path.

like image 26
DarkDust Avatar answered Sep 19 '22 16:09

DarkDust


It's not clear which of the following cases you're asking about, so here's a quick answer for both:

  1. If you're starting with a single file that contains your content This is the most common case. In general, there are three steps to creating a playable HlS stream from source material.
  • for each desired output level (let’s say Bitrate for simplicity), you need to create a collection of segmented .ts files.
  • For each output level you need a playlist manifest (m3u8) that contains the list of segment files making up the content.
  • For the whole stream you need a single master manifest (another m3u8) that lists the playlists.

FFMpeg can do all three of these.

  1. If you're starting with a collection of .ts files If you really are starting with a collection of .ts files, you could either hand-build an m3u8 file as described in the previous answer, or you could write a script to do it.

In either case, there are some considerations for the .ts files:

  • If the segment files do not belong to an uninterrupted sequence (as they would if they were transcoded from a single source clip for use in HLS), you’ll need to insert EXT-X-DISCONTINUITY tags between segments that don’t have the same encoding characteristics or that don’t have monotonically increasing PTS (presentation timestamp) values.

  • While the segments don't need to all be the same length, the longest one must not exceed the (integer) number of seconds specified in the EXT-X-TARGETDURATION tag.

  • "For VOD content, the average segment bit rate MUST be within 10% of the AVERAGE-BANDWIDTH attribute"

When you've built your m3u8 file, it helps to run it through a validator to find any problems.This is a lot easier than scratching your head wondering why an HLS stream plays poorly or inconsistently across players/browsers.

  • mediaStreamValidator on macOS is very good https://developer.apple.com/documentation/http_live_streaming/about_apple_s_http_live_streaming_tools
  • Also consider the online tool at Theo: http://inspectstream.theoplayer.com/
like image 178
thornfish Avatar answered Sep 19 '22 16:09

thornfish