-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitch-and-ffmpeg-with-some-youtube-dl-help-fetch-from-live-stream-to-local-file.html
56 lines (55 loc) · 12.5 KB
/
twitch-and-ffmpeg-with-some-youtube-dl-help-fetch-from-live-stream-to-local-file.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Twitch and FFmpeg and Youtube-dl: Fetch from live stream to local file - Toto do stuff</title><meta name="description" content="(Using Windows PowerShell, adapt for UNIX bash shouldn’t be a big issue) So something nice with youtube-dl is like you can ask not to download…"><meta name="generator" content="Publii Open-Source CMS for Static Site"><link rel="canonical" href="https://totetmatt.github.io/twitch-and-ffmpeg-with-some-youtube-dl-help-fetch-from-live-stream-to-local-file.html"><link rel="alternate" type="application/atom+xml" href="https://totetmatt.github.io/feed.xml"><link rel="alternate" type="application/json" href="https://totetmatt.github.io/feed.json"><meta property="og:title" content="Twitch and FFmpeg and Youtube-dl: Fetch from live stream to local file"><meta property="og:site_name" content="Toto do stuff"><meta property="og:description" content="(Using Windows PowerShell, adapt for UNIX bash shouldn’t be a big issue) So something nice with youtube-dl is like you can ask not to download…"><meta property="og:url" content="https://totetmatt.github.io/twitch-and-ffmpeg-with-some-youtube-dl-help-fetch-from-live-stream-to-local-file.html"><meta property="og:type" content="article"><style>:root{--body-font:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";--heading-font:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";--logo-font:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";--menu-font:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Fira Sans","Droid Sans","Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"}</style><link rel="stylesheet" href="https://totetmatt.github.io/assets/css/style.css?v=825c89ac06c7215b642eda05e8a14751"><script type="application/ld+json">{"@context":"http://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://totetmatt.github.io/twitch-and-ffmpeg-with-some-youtube-dl-help-fetch-from-live-stream-to-local-file.html"},"headline":"Twitch and FFmpeg and Youtube-dl: Fetch from live stream to local file","datePublished":"2020-10-13T20:04","dateModified":"2020-10-13T20:04","description":"(Using Windows PowerShell, adapt for UNIX bash shouldn’t be a big issue) So something nice with youtube-dl is like you can ask not to download…","author":{"@type":"Person","name":"Totetmatt","url":"https://totetmatt.github.io/authors/totetmatt/"},"publisher":{"@type":"Organization","name":"Totetmatt"}}</script></head><body><div class="site-container"><header class="top" id="js-header"><a class="logo" href="https://totetmatt.github.io/">Toto do stuff</a></header><main><article class="post"><div class="hero"><figure class="hero__image hero__image--overlay"><img src="https://totetmatt.github.io/media/website/bg.jpg" srcset="https://totetmatt.github.io/media/website/responsive/bg-xs.jpg 300w, https://totetmatt.github.io/media/website/responsive/bg-sm.jpg 480w, https://totetmatt.github.io/media/website/responsive/bg-md.jpg 768w, https://totetmatt.github.io/media/website/responsive/bg-lg.jpg 1024w, https://totetmatt.github.io/media/website/responsive/bg-xl.jpg 1360w, https://totetmatt.github.io/media/website/responsive/bg-2xl.jpg 1600w" sizes="(max-width: 1600px) 100vw, 1600px" loading="eager" alt=""></figure><header class="hero__content"><div class="wrapper"><div class="post__meta"><time datetime="2020-10-13T20:04">20/10/13</time></div><h1>Twitch and FFmpeg and Youtube-dl: Fetch from live stream to local file</h1><div class="post__meta post__meta--author"><a href="https://totetmatt.github.io/authors/totetmatt/" class="feed__author invert">Totetmatt</a></div></div></header></div><div class="wrapper post__entry"><p><em>(Using Windows PowerShell, adapt for UNIX bash shouldn’t be a big issue)</em></p><h1 id="record-a-live-stream">Record a live stream</h1><p>So something nice with youtube-dl is like you can ask not to download the media but to fetch for the media link :</p><pre><code>>> youtube-dl -g http://something
youtube-dl -g https://www.youtube.com/watch?v=RJt01u4yrLQ
https://r2---sn-h0jeened.googlevideo.com/videoplayback?expire=1[...]
</code></pre><p>If you use that for a twitch channel that is streaming live, it returns you the HLS stream.</p><pre><code>>> youtube-dl -g https://www.twitch.tv/farore_de_firone
https://video-weaver.ber01.hls.ttvnw.net/v1/playlist/CpkEQusnrcdffNI3[..]MA2c4.m3u8
</code></pre><p>It by default binds to the best quality video, but you can check and select all format available using <code>-F</code></p><pre><code>>> youtube-dl -F https://www.twitch.tv/farore_de_firone
[twitch:stream] farore_de_firone: Downloading stream GraphQL
[twitch:stream] farore_de_firone: Downloading access token JSON
[twitch:stream] 39653517372: Downloading m3u8 information
[info] Available formats for 39653517372:
format code extension resolution note
audio_only mp4 audio only 2k , mp4a.40.2
160p mp4 284x160 230k , avc1.4D401F, 30.0fps, mp4a.40.2
360p mp4 640x360 630k , avc1.4D401F, 30.0fps, mp4a.40.2
480p mp4 852x480 1262k , avc1.4D401F, 30.0fps, mp4a.40.2
720p60 mp4 1280x720 3257k , avc1.4D401F, 60.0fps, mp4a.40.2
1080p60__source_ mp4 1920x1080 6713k , avc1.64002A, 60.0fps, mp4a.40.2 (best)
</code></pre><p><em>You could even only have the audio-stream</em></p><p>And to select it</p><pre><code>>> youtube-dl -f 160p -g https://www.twitch.tv/farore_de_firone
</code></pre><p>So with this link, you can use ffmpeg to record localy the stream to your computer (and have your own reaplay / VOD without the “disagreement” of Twitch VOD :) )</p><pre><code>>> ffmpeg -i "$(youtube-dl -f 720p60 -g https://www.twitch.tv/farore_de_firone)" -c copy stream.20201012.mp4
</code></pre><p>And here it’s quite simple “dump” of the running script. Nothing prevent you to add some filters, reencoding that adapt to your needs.</p><h1 id="mixing-multiple-stream">Mixing multiple stream</h1><p>Let’s have some fun, there is some streamers that plays together on the same game. Usually, you can watch their POV at the sametime with the <strong>Twitch Squad</strong> mechanism or <strong>Multitwitch</strong> application. But would it be possible to record a file in such way ?</p><p>Actually yes, ffmpeg can take multiple video input and transform it on the fly via the filter complex to render all the video on the same stream.</p><p>There is a nice topic on Stackoverflow that explain how to simply stack multiple video : <a href="https://stackoverflow.com/questions/11552565/vertically-or-horizontally-stack-mosaic-several-videos-using-ffmpeg">https://stackoverflow.com/questions/11552565/vertically-or-horizontally-stack-mosaic-several-videos-using-ffmpeg</a></p><p>Example merging 2 videos :</p><pre><code>>> ffmpeg -i "$(youtube-dl -g https://www.twitch.tv/antoinedaniellive)" \
-i "$(youtube-dl -g https://www.twitch.tv/soon)" \
-filter_complex vstack=inputs=2 \
-map 0:a \
output.mp4
</code></pre><p>Example merging 4 videos :</p><pre><code>>> ffmpeg -i "$(youtube-dl -f 160p -g https://www.twitch.tv/antoinedaniellive)" \
-i "$(youtube-dl -f 160p -g https://www.twitch.tv/soon)" \
-i "$(youtube-dl -f 160p -g https://www.twitch.tv/angledroit )" \
-i "$(youtube-dl -f 160p -g https://www.twitch.tv/etoiles)" \
-filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[v]" -map "[v]" \
-map 0:a \
-y output.mp4
</code></pre><p><em>Note</em> : it’s better to stack video vertically. Horizontal stack does works but then some services (like twitter) won’t accept the video because the image ratio will be too extreme.</p><p>The <code>-map 0:a</code> here is necessary to select which audio you want to have.</p><p>The format mkv also allow to record multiple video stream within one file that you can selected after that :</p><pre><code>>> ffmpeg -i "$(youtube-dl -g https://www.twitch.tv/alphacast)" \
-i "$(youtube-dl -g https://www.twitch.tv/colas_bim)" \
-i "$(youtube-dl -g https://www.twitch.tv/eventisfr)" \
-i "$(youtube-dl -g https://www.twitch.tv/fusiow)" \
-map 0:1 -map 1:1 -map 2:1 -map 3:1 -map 0:0 \
-c copy \
out.mkv
</code></pre></div><footer class="wrapper post__footer"><p class="post__last-updated">This article was updated on 20/10/13</p><div class="post__share"></div><div class="post__bio bio"><div class="bio__info"><h3 class="bio__name"><a href="https://totetmatt.github.io/authors/totetmatt/" class="invert" rel="author">Totetmatt</a></h3></div></div></footer></article><nav class="post__nav"><div class="post__nav-inner"><div class="post__nav-prev"><svg width="1.041em" height="0.416em" aria-hidden="true"><use xlink:href="https://totetmatt.github.io/assets/svg/svg-map.svg#arrow-prev"/></svg> <a href="https://totetmatt.github.io/extract-chapters-youtube-media.html" class="invert post__nav-link" rel="prev"><span>Previous</span> Extract chapters from Youtube Media</a></div><div class="post__nav-next"><a href="https://totetmatt.github.io/how-to-capture-your-bonzomatic-with-ffmpeg.html" class="invert post__nav-link" rel="next"><span>Next</span> How to Capture your Bonzomatic with FFmpeg </a><svg width="1.041em" height="0.416em" aria-hidden="true"><use xlink:href="https://totetmatt.github.io/assets/svg/svg-map.svg#arrow-next"/></svg></div></div></nav><div class="post__related related"><div class="wrapper"><h2 class="h5 related__title">You should also read:</h2><article class="related__item"><div class="feed__meta"><time datetime="2014-06-15T09:55" class="feed__date">14/06/15</time></div><h3 class="h1"><a href="https://totetmatt.github.io/lets-play-gephi-streaming-api-the-hidden-websocket.html" class="invert">Let's Play Gephi : Streaming API - The 'hidden' Websocket</a></h3></article><article class="related__item"><div class="feed__meta"><time datetime="2013-08-04T10:22" class="feed__date">13/08/04</time></div><h3 class="h1"><a href="https://totetmatt.github.io/augentwitt-pictures-grabber-from-twitter.html" class="invert">Augentwitt - Pictures Grabber from Twitter</a></h3></article><article class="related__item"><div class="feed__meta"><time datetime="2013-09-16T19:18" class="feed__date">13/09/16</time></div><h3 class="h1"><a href="https://totetmatt.github.io/gephi-and-the-streaming-module.html" class="invert">Gephi and the Streaming module</a></h3></article></div></div></main><footer class="footer"><div class="footer__copyright"><p>Powered by <a href="https://getpublii.com" target="_blank" rel="nofollow noopener">Publii Static CMS</a></p></div><button class="footer__bttop js-footer__bttop" aria-label="Back to top"><svg><title>Back to top</title><use xlink:href="https://totetmatt.github.io/assets/svg/svg-map.svg#toparrow"/></svg></button></footer></div><script>window.publiiThemeMenuConfig = {
mobileMenuMode: 'sidebar',
animationSpeed: 300,
submenuWidth: 'auto',
doubleClickTime: 500,
mobileMenuExpandableSubmenus: true,
relatedContainerForOverlayMenuSelector: '.top',
};</script><script defer="defer" src="https://totetmatt.github.io/assets/js/scripts.min.js?v=f4c4d35432d0e17d212f2fae4e0f8247"></script><script>var images = document.querySelectorAll('img[loading]');
for (var i = 0; i < images.length; i++) {
if (images[i].complete) {
images[i].classList.add('is-loaded');
} else {
images[i].addEventListener('load', function () {
this.classList.add('is-loaded');
}, false);
}
}</script></body></html>