tôi sẽ được sử dụng cho sự kiện trực tiếp này là một ví dụ:
https://www.youtube.com/watch?v=6aXR-SL5L2o
Thứ nhất, danh sách các định dạng cho video:
➜ youtube_live_test 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)
Chọn định dạng mà bạn muốn tải về, và tìm nạp URL HUS m3u8 của video từ tệp kê khai. Tôi sẽ sử dụng 95 mp4 720p HLS , h264, aac @256k
ví dụ này:
➜ youtube_live_test 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
Bây giờ bạn có danh sách nhạc HLS, bạn có thể mở URL này trong VLC và lưu nó sử dụng "Record", hoặc viết một lệnh ffmpeg nhỏ:
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
Nếu bạn đã chọn định dạng mình thích, thay vì sao chép và dán, bạn có thể sử dụng '$()' (thay thế lệnh bash): 'ffmpeg -i $ (youtube-dl -f 22 -g https: // www .youtube.com/watch \? v \ = 6aXR-SL5L2o) -c sao chép omg1.ts' – fbehrens