I want to restream 3 youtube videos (each one is a live webcam) in this way: they would run one after the other, but each one runs for only 1 minute. All this in a loop. So my live stream would eventually look like this: cam1, cam2, cam3, cam1, cam2, cam3, ... I have tried to used youtube-dl and ffmpeg (these are my preferred command line tools) to download each stream, let it run for 1 minute and restream it. The problem is that I have to start ffmpeg each time. So when it stops and starts again, the live stream stops and starts again (after about 15 seconds). Here is my code (for bash):
The main script: (FILE is an array with the 3 URLs for the videos)
for URL in "${FILE[@]}"
do
timeout 1m /usr/local/bin/get_livestream.sh $URL
done
and get_livestream.sh:
youtube-dl -q -o - -- $1 | ffmpeg -re -loglevel warning -hide_banner \
-i - -s 960x540 -c:v libx264 -b:v 2M -c:a copy \
-strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 2100k \
-f flv rtmp://live.twitch.tv/app/<key>