2019-09-11
How do you use youtube-dl to download live streams (that are live)?
stackoverflow
Question

Just wondering if that's possible or not- when I copy the video URL into YouTube-dl it spits out

[https @ 0x7fc351416080] inflate return value: -3, incorrect header check
Last message repeated 15 times

After that it spits out of couple lines of red text that doesn't seem to want to copy in properly, so I took a snippet

Picture

Does anyone know if this is possible?

Answer
1

I'll be using this Live Event as an example:

https://www.youtube.com/watch?v=6aXR-SL5L2o

First, list the formats for the video:

$  ~ youtube-dl --list-formats https://www.youtube.com/watch\?v\=6aXR-SL5L2o
[youtube] 6aXR-SL5L2o: Downloading webpage
[youtube] 6aXR-SL5L2o: Downloading video info webpage
[youtube] 6aXR-SL5L2o: Extracting video information
[youtube] 6aXR-SL5L2o: Downloading formats manifest
[youtube] 6aXR-SL5L2o: Downloading MPD manifest
[info] Available formats for 6aXR-SL5L2o:
format code  extension  resolution note
91           mp4        144p       HLS , h264, aac  @ 48k
92           mp4        240p       HLS , h264, aac  @ 48k
93           mp4        360p       HLS , h264, aac  @128k
94           mp4        480p       HLS , h264, aac  @128k
95           mp4        720p       HLS , h264, aac  @256k (best)

Pick the format you wish to download, and fetch the HLS m3u8 URL of the video from the manifest. I'll be using 95 mp4 720p HLS , h264, aac @256k for this example:

➜  ~ youtube-dl -f 95 -g https://www.youtube.com/watch\?v\=6aXR-SL5L2o
https://manifest.googlevideo.com/api/manifest/hls_playlist/id/6aXR-SL5L2o.1/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/itag%3D140/sgovp/itag%3D136/hls_chunk_host/r16---sn-ab5l6ne7.googlevideo.com/gcr/us/playlist_type/DVR/mm/32/mn/sn-ab5l6ne7/ms/lv/mv/u/pl/17/dover/3/fexp/9416126,9416891,9419451,9422596,9423554,9427790,9428193,9428398,9428974,9429011,9431012,9431164,9432683,9433096,9433946,9434343,9434833,9434847,9435186,9435741/upn/UNF1TiBtavY/sver/3/mt/1462544320/ip/64.125.177.124/ipbits/0/expire/1462565936/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,gcr,playlist_type,mm,mn,ms,mv,pl/signature/67EC57CB964D9D944DE2E1AB40F0E496DA2C73B4.8FBEF1974DF9DB1E614B9C96BA0FF8E52076B04F/key/dg_yt0/playlist/index.m3u8

Now that you have the HLS playlist, you can open this URL in VLC and save it using "Record", or write a small ffmpeg command:

ffmpeg -i \
https://manifest.googlevideo.com/api/manifest/hls_playlist/id/6aXR-SL5L2o.1/itag/95/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/cmbypass/yes/goi/160/sgoap/itag%3D140/sgovp/itag%3D136/hls_chunk_host/r16---sn-ab5l6ne7.googlevideo.com/gcr/us/playlist_type/DVR/mm/32/mn/sn-ab5l6ne7/ms/lv/mv/u/pl/17/dover/3/fexp/9416126,9416891,9419451,9422596,9423554,9427790,9428193,9428398,9428974,9429011,9431012,9431164,9432683,9433096,9433946,9434343,9434833,9434847,9435186,9435741/upn/UNF1TiBtavY/sver/3/mt/1462544320/ip/64.125.177.124/ipbits/0/expire/1462565936/sparams/ip,ipbits,expire,id,itag,source,requiressl,ratebypass,live,cmbypass,goi,sgoap,sgovp,hls_chunk_host,gcr,playlist_type,mm,mn,ms,mv,pl/signature/67EC57CB964D9D944DE2E1AB40F0E496DA2C73B4.8FBEF1974DF9DB1E614B9C96BA0FF8E52076B04F/key/dg_yt0/playlist/index.m3u8 \
-c copy output.ts
How do you use youtube-dl to download live streams (that are live)?
See more ...