ゴジラ

Downloading live video with youtube-dl

You'll need:

Find the possible resolutions available for the stream,

root@box:~# youtube-dl --list-formats https://www.youtube.com/watch?v=oD8kq6xjNNo
[youtube] oD8kq6xjNNo: Downloading webpage
[youtube] oD8kq6xjNNo: Downloading video info webpage
[youtube] oD8kq6xjNNo: Extracting video information
[youtube] oD8kq6xjNNo: Downloading formats manifest
[youtube] oD8kq6xjNNo: Downloading MPD manifest
[info] Available formats for oD8kq6xjNNo:
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
96           mp4        1080p      HLS , h264, aac  @256k (best)

Now we pick the 1080p stream to download (#96),

96           mp4        1080p      HLS , h264, aac  @256k (best)

Next, Find the stream/playlist URL,

root@box:~# youtube-dl -f 96 -g https://www.youtube.com/watch?v=oD8kq6xjNNo

We get,

root@box:~# youtube-dl -f 96 -g https://www.youtube.com/watch?v=oD8kq6xjNNo
https://manifest.googlevideo.com/api/manifest/hls_playlist/id/............./key/dg_yt0/playlist/index.m3u8

Now pass the output URL into avconv to copy into a local file,

avconv -i "https://manifest.googlevideo.com/api/manifest/hls_playlist/id/............./key/dg_yt0/playlist/index.m3u8" -c copy output.ts

You'll then get the following output,

avconv version 11.7-6:11.7-1~deb8u1, Copyright (c) 2000-2016 the Libav developers
built on Jun 12 2016 21:51:35 with gcc 4.9.2 (Debian 4.9.2-10)
[mpegts @ 0x1db2bc0] Estimating duration from bitrate, this may be inaccurate
[hls,applehttp @ 0x18db4c0] Estimating duration from bitrate, this may be inaccurate
Input #0, hls,applehttp, from 'https://manifest.googlevideo.com/api/manifest/hls_playlist/id/............./key/dg_yt0/playlist/index.m3u8':
  Duration: 00:03:09.05, start: 735.026000, bitrate: 123 kb/s
  Program 0
    Metadata:
      variant_bitrate : 0
    Stream #0.0: Audio: aac, 48000 Hz, stereo, fltp, 123 kb/s
    Stream #0.1: Video: h264 (High), yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 30 fps, 90k tbn, 60 tbc
Output #0, mpegts, to 'output.ts':
  Metadata:
    encoder         : Lavf56.1.0
    Stream #0.0: Video: libx264, yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], q=2-31, 90k tbn, 90k tbc
    Stream #0.1: Audio: aac, 48000 Hz, stereo, 123 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press ctrl-c to stop encoding
[mpegts @ 0x1db2bc0] Continuity check failed for pid 0 expected 1 got 0
[mpegts @ 0x1db2bc0] Continuity check failed for pid 4095 expected 1 got 0
[mpegts @ 0x1db2bc0] Continuity check failed for pid 0 expected 1 got 0
[mpegts @ 0x1db2bc0] Continuity check failed for pid 4095 expected 1 got 0
.....

The output will be continously written out to the file output.ts, Press ctrl-c to stop encoding and then you can access the video stores in the output.ts file.


Last modified: December 06 2019 14:21:55