Download m3u8 video with PowerShell

0

Farouk asked how to download m3u8 videos at: Downloading m3u8 videos

I read m3u8 videos may be downloaded with ffmpeg:
ffmpeg -i "URL.m3u8" -c copy -bsf:a aac_adtstoasc "output.mp4"

Running the code got me this error:

This may result in incorrect timestamps in the output file.
[mp4 @ 035f0f60] Non-monotonous DTS in output stream 0:0; previous: 466839031, current: 466838873; changing to 466839032.   
This may result in incorrect timestamps in the output file.
frame=1706633 fps=290 q=-1.0 Lsize=17130325kB time=01:26:27.15 bitrate=27053.7kbits/s
video:15984919kB audio:1133157kB subtitle:0 data:0 global headers:0kB muxing overhead 0.071561%

I then ran it without -bsf option, and got this error:

[mp4 @ 04a00060] Malformed AAC bitstream detected: use audio bitstream  
filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)  
av_interleaved_write_frame(): Operation not permitted
frame=    2 fps=0.0 q=-1.0 Lsize=       1kB time=00:00:00.04 bitrate= 245.6kbits/s
video:0kB audio:0kB subtitle:0 data:0 global headers:0kB muxing overhead 55.839417%
Conversion failed!

So I opened the m3u8 file and found the file had following format:

#EXT-X-VERSION:5
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:5.547578,
#EXT-X-BYTERANGE:990196@18
URL
#EXTINF:5.297311,
#EXT-X-BYTERANGE:2108796@990214
URL
#EXTINF:4.504800,
#EXT-X-BYTERANGE:480152@3099010
URL
#EXTINF:6.006400,
etc...
#EXT-X-ENDLIST

What worked was to just get the URL list (filtered) using regexp, download them via PowerShell, then join with ffmpeg.

Zimba

Posted 2019-04-19T16:58:29.770

Reputation: 107

Answers

-1

To download with powershell:

Invoke-WebRequest -Uri "URL.mp4" -outfile "1.mp4"
Invoke-WebRequest -Uri "NextURL.mp4" -outfile "2.mp4"
etc.

To join with CMD:

(for %i in (*.mp4) do @echo file '%i') > mylist.txt
ffmpeg -f concat -i mylist.txt -c copy "video.mp4"

Zimba

Posted 2019-04-19T16:58:29.770

Reputation: 107