How to download a m3u8/TS file

A M3U8 stands for MP3 URL UTF-8-encoded playlist file and is the basis for the HTTP Live Streaming (HLS) format originally developed by Apple to stream audio and video content. It is developed as an alternative to Flash video format (flv).

Here is an example playlist.



As can be seen the source files for m3u8 format are packaged in an MPEG-2 Transport Stream (transport stream, MPEG-TS, MTS or TS) and broken up into a series of smaller chunks (.ts files). These .ts files are referenced in a .M3U8 playlist file index.

A player on the client side will read the index file to request the chunks in the correct sequence. Depending on the bandwidth, the client will then choose a chunk from an appropriate bitrate. 

Here's how to download a m3u8 file and stitch the .ts chunks together.

ffmpeg -user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/601.7.8 (KHTML, like Gecko) Version/9.1.3 Safari/537.86.7" -i <path_to_.m3u8_file> -c copy <output_file.mkv>