Bart Simons

Bart Simons


Thoughts, stories and ideas.

Bart Simons
Author

Share


Tags


.net .net 5 .net core Apache C# CentOS LAMP NET Framework Pretty URLs Windows Server WireGuard WireGuard.io access log add analysis android api at the same time authentication authorization automate automation azure azurerm backup bash basics batch bootstrap build capture cheat sheet chromium chroot class cli click to close code coverage code snippet command line commands compile compiling compression containers control controller controlling convert cpu usage create credentials csv csvparser curl data dd deployment desktop detect devices disable diskpart dism distributed diy docker dom changes dotnet core drivers ease of access encryption example export file transfer files fix folders framework generalize getting started ghost ghost.org gui guide gunicorn gzip html html tables icewarp igd imagex import inotify install installation interactive ios iphone itunes java javascript jquery json kiosk kotlin linux live load data loading screen lock screen loopback audio lxc lxd lxml macos manage manually message messages minio mirrored mod_rewrite monitor monitoring mstest mutationobserver mysql net 5 nexmo nginx no oobe node node.js nodejs not installing notification notifications object storage on desktop one command openssl owncloud parallels parallels tools parse perfect philips hue play port forwarding portainer.io powershell processing ps-spotify python quick raspberry pi record rip ripping rsync rtmp save save data sbapplication scraping script scripting scriptingbridge scripts security send server service sharedpreferences sms songs sonos spotify spotify api spotlight ssh stack streaming streamlink studio sudo swarm swift sync sysprep system audio systemd tables terminal testing tracking tutorial twilio ubiquiti ubuntu ubuntu 18.04 ui code unifi unlock unsplash source upnp uptime usb tethering wallpapers wasapi website websites webview windows windows 10 without itunes without oobe workaround xaml

Playing and saving at the same time with streamlink

I have recently got my hands dirty with streamlink, because I needed a CLI tool to create video recordings of YouTube and Twitch live streams, since YouTube has a buffer limit, and Twitch doesn't even support scrolling back in time during a livestream. Streamlink seemed like the perfect fit for my idea, and the results were good: nice and crisp full VODs of my favorite streaming content. But there was only one open question left to make it really perfect: can it play and record at the same time?

Here's how I did it

First of all, you need to be running macOS or Linux. Windows might work if you use Windows 10 with the Windows subsystem for Linux installed, but that's untested so your results may vary.

The solution that exists for now is to use the tee utility to pipe the stdout of streamlink to a transport stream (.ts) file, and pipe it again to your favourite video player.

streamlink -O url stream | tee recording.ts | vlc - 

Help: my recording.ts file is corrupt - what should I do?

That's not an uncommon problem, in fact: those files are prone to breaking if for example the last frame is not fully written yet when you cancel streamlink. You can always use ffmpeg afterwards to fix this automagically:

ffmpeg -err_detect ignore_err -i recording.ts -c copy recording-fixed.ts

This should work as far as I know.

Is there a better way?

Of course, this is not the best solution: a PR is currently open over at GitHub at:

https://github.com/streamlink/streamlink/pull/920

Hopefully the record flag will be introduced so that you don't have to double pipe the stream. Good luck with getting this to work 👍

Bart Simons
Author

Bart Simons

View Comments