I have the m3u8 file and the key.bin, inside the m3u8 file is:
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128,URI="key.bin"
#EXTINF:6.000000,
segment-0.ts
...
#EXTINF:4.416667,
segment-159.ts
#EXT-X-ENDLISTand inside the key.bin file is
Ú{±€rl”ÜJÌy«‡móHow do I download this as an mp4 using ffmpeg or youtube-dl?.
23 Answers
You can use ffmpeg like so:
ffmpeg -i video.m3u8 -c copy -bsf:a aac_adtstoasc video.mp4Also if the urls are https you can add https to allowed protocols like so:
ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i video.m3u8 -c copy -bsf:a aac_adtstoasc video.mp4Original article:Download encrypted HLS content with ffmpeg - davd.io
If you encounter a field such as EXT-X-KEY, the URI value first needs to be
resolved, relative to the playlist URI. So if you have this:
then the resultant URI will be:
once thats done, you can get the data from the URI, typically 16 bytes or more. You can then resolve a segment URI:
and download as normal. Next you can decrypt the segment using AES-CBC, using
the data from key.bin, as both the AES key, and the CBC IV. After decrypting,
you'll need to remove any padding, if it exists. Repeat this process for all
the segments.
If you're using youtube-dl -o file.mp4 "m3u8-URL", you might need to might need to pass proper headers for youtube-dl/ffmpeg to be allowed to download the key. use the --user-agent "USERAGENT" and --referer "REFERRER_URL" argument. You need to use same user-agent as your browser-you can find yours easily at and referer is the main URL in the browser from where you sniffed out the m3u8 URL)
Credit goes to the guy from reddit who gave the solution.
1