restreamer
restreamer copied to clipboard
Set-up a backup stream for YouTube live streaming
Hello!
First of all my appreciations for the project. I found it very easy to use and setup with docker.
I'm currently using a surveillance webcam as source, which is connected with a 4G LTE mobile connection. This stream is given to Restreamer as source, as I said before, then as output I send it to YouTube RTMP server for live streaming.
Sometimes happens that connections from source fails for some minutes, unfortunately I'm unable to have a backup connection right now. So the problem when the input stream resumes is that YouTube has already closed the live streaming. The only way to resume the live streaming on YouTube, as far as I know, is to re-open the YT Studio and wait the connection between Restreamer and YT. In this case, If I browse the Restreamer web frontend, it returns the streaming is already up and running on YT, which is maybe reported in this way because RTMP server is not rejecting the stream, but on YT is not running a live streaming or a video or whatever. :)
Anyway, I restart the output stream on Restreamer with YT Studio open and after some seconds the live streaming on YT works fine again. The "new" live streaming is using another YouTube URL so the live streaming I've set-up earlier is no longer valid. This is a problem because the streaming is embedded on some not-public web pages. As you can imagine I can not change the embed URL in my web pages every 2-3 hours.
To avoid this behaviour I've though to use a static image as "backup stream", and send it to YT as failover when mobile connection is down.
Is that possible with Restreamer? Should I use ffmpeg to send a static images as stream to the YouTube backup RTMP server? It could be a workaround? I'm open to your advices.
Last but not least, Restreamer is running on a Docker container on Azure. I prefer to use YT as live streaming and not the OOTB player because on YT every live streaming is automatically recorded and I've some interesting functions (live chat, user engagements etc.). This preventing the question: why are not using the Restreamer player? :)
Thanks!
What you describe is very typical. That's why we're working on a built-in solution for this.
As a temporary workaround you can use ffmpeg to send a video of a static image to the backup destination. I will provide you the basic commands. You may need to adjust them to your needs.
First, you encode the image to a short video snippet with the same resolution, bitrate, and framerate as the stream from the camera. YT also requires audio, so we'll add a some silence audio:
ffmpeg -loop 1 -framerate 25 -re -i image.jpg -f lavfi -i anullsrc=r=44100:cl=stereo -vf scale=1280x720 -c:v libx264 -r 25 -g 50 -preset ultrafast -tune zerolatency -b:v 2M -c:a aac -b:a 32k -shortest -movflags +faststart -t 10 -y -f mp4 fallback.mp4
Now you have the snippet (fallback.mp4
) that can then be used to stream to YT in a loop:
ffmpeg -stream_loop -1 -re -i fallback.mp4 -codec copy -f flv "rtmps://b.rtmp.youtube.com/live2?backup=1/_YOUR_KEY_"
This way, you don't need to encode the static image all the time, you're just looping the snippet.
Thanks @ioppermann for the ffmpeg backup solution but for some reason youtube keeps switching to the backup even though restreamer is still sending towards youtube (maybe short interruptions?) We are using restreamer to publish a wild animal camera to the public and i really would love to see a built in backup functionality. Do you have any estimate on when such a function could be implemented? Or any idea why youtube switches to backup? Also it seems that youtube is not switching from the backup stream to the main stream once it activated.
Hey @Pepozzo @MrCoala Have you already tested the latest version? The YouTube Live preset can send to the primary and secondary stream simultaneously.
Hi @Pepozzo We are closing your issue https://github.com/datarhei/restreamer/issues/259.
This may be due to the following reasons:
- Problem/inquiry has been solved
- The ticket remained unanswered by you for a more extended time
- The problem was explained and handled in another ticket
You can reopen this ticket at any time!
Please do not open related tickets twice. Always answer/ask in the original issue with the same problem.
Your datarhei team //Sven