Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make youtube-dl or streamlink stop after a certain period of time when downloading a live stream

I’m the unofficial historian for a popular 24/7 live feed. I wrote a script to use streamlink (fork of livestreamer) to download the stream constantly. Then i have a script to upload the captured video to YouTube as unlisted for the stream owner. I use a shell script and have the file names be dates and times.

I’ve also used youtube-dl. For both, The maximum captured time appears to be 6 hours because it’ll stop after that amount of time. To address this, I wrote a script to restart the capture when it stops after sleeping for 30 seconds (safety in case of runaway loop) so this isn’t an issue either.

What i am trying to do is to either set my stream capture (whether it’s youtube-dl or streamlink it doesn’t matter) to stop after a shorter interval, say 2 hours. I could also split up the file into 3 parts but i don’t know if that would require re-encoding. If it does, that’s not an option because all of this is done on a VPS with limited resources.

The reason I am trying to split up the files or capture in a shorter time period is because 6 hours is too dang long to easily navigate a YouTube video. On mobile, trying to seek to a specific time is near impossible. Desktop isn’t much easier because you need to be very precise.

like image 578
Programmer4Life Avatar asked Oct 16 '25 15:10

Programmer4Life


1 Answers

timeout 2h <your command>

the above will end the command after 2hrs..you can also pass it different kill signals..

http://man7.org/linux/man-pages/man1/timeout.1.html

like image 76
MostWanted Avatar answered Oct 18 '25 12:10

MostWanted



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!