Twitch and FFmpeg and Youtube-dl: Fetch from live stream to local file
(Using Windows PowerShell, adapt for UNIX bash shouldn’t be a big issue)
Record a live stream#
So something nice with youtube-dl is like you can ask not to download the media but to fetch for the media link :
If you use that for a twitch channel that is streaming live, it returns you the HLS stream.
It by default binds to the best quality video, but you can check and select all format available using -F
You could even only have the audio-stream
And to select it
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 :) )
And here it’s quite simple “dump” of the running script. Nothing prevent you to add some filters, reencoding that adapt to your needs.
Mixing multiple stream#
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 Twitch Squad mechanism or Multitwitch application. But would it be possible to record a file in such way ?
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.
There is a nice topic on Stackoverflow that explain how to simply stack multiple video : https://stackoverflow.com/questions/11552565/vertically-or-horizontally-stack-mosaic-several-videos-using-ffmpeg
Example merging 2 videos :
Example merging 4 videos :
Note : 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.
The -map 0:a here is necessary to select which audio you want to have.
The format mkv also allow to record multiple video stream within one file that you can selected after that :