Convert m3u8 url to mp4

Posted by Andrew Denner on January 25, 2021 · 1 min read

In my previous post, I covered how to combine two mp4 streams (one audio and one video) together. Next in the series is how to download a m3u8 file (that you clearly have permission to download) and convert the enclosed .ts files into one mp4 file.

As before, ffmpeg is the answer to all your problems (and likely will be the cause of several more… but that is a story for another post.)

As a reminder, if you don’t already have ffmpeg, installation is quite simple (assuming a debian based os)

sudo apt update
sudo apt install ffmpeg

After the install process it is as simple as using the following command:

ffmpeg -i [url of m3u8] -c copy -bsf:a aac_adtstoasc output.mp4

It will take a while and all of the .ts files listed in the m3u8 will be listed as “opening https://…/foo.ts for reading” and eventually you will have your .mp4 file. I would then recomend reading the next blog post in the series on how to transcode your mp4 into a h265 file to save on space.