Downloading m3u8 streams as .mp4 Videos

Just hit Download on Episode 1 of Game of Thrones. Fear I just lost May 2014.
Unknown

Recently I was taking a course that used streamed video on the course platform. As I prefer to work offline (less distractions), I wanted to save the streams as video. Turns out, the video streams were easy to identify. Simply right-clicking on the page and selecting «View Page Source», then looking for the video (they used .m3u8 streams).

Once identified, e.g. (using XXXXX to anonymize the name, sorry, private):

https://XXXXX.video.XXXXX.de/XXXXX/XXXXX/output/XXXXX.m3u8

you can use ffmpeg to download it, e.g.:

ffmpeg -i “https://XXXXX.video.XXXXX.de/XXXXX/XXXXX/output/XXXXX.m3u8” -c copy xxxxx.mp4

(No, this specific command line will not work, as the stream is anonymized and does not exist, or should not exist. But it shows the command, just replace the link with the stream you want to download.)

The files were rather large, but could be rescaled and compressed, again with ffmpeg:

ffmpeg -i xxxxx.mp4 -vf “scale=720:480:force_original_aspect_ratio=decrease,pad=720:480:(ow-iw)/2:(oh-ih)/2” -vcodec libx264 -crf 23 -preset medium -acodec aac -b:a 128k rdx_xxxxx.mp4

In this case, it turns the video into 720×480 and adds black bars (letterboxing) if the aspect ratio does not fit. It’s only one of countless settings, see the ffmpeg help for more information.

And yeah, I guess vlc works as well, if you open the link as stream and save it into a file. But you can use .zsh scripts to automate downloading of multiple videos with ffmpeg. Essentially just creating a text file with .zsh ending, putting the command lines in it after “#!/bin/zsh” in the first line, and executing with with “zsh name.zsh” (all without the quotation marks here). Not sure you can do so with a GUI like vlc.

So, yeah, getting these m3u8 stream offline as video works very well.