Is it possible to seamlessly switch between 2 WebRTC inputs to an RTMP push output? #4326
Replies: 1 comment
-
The use scenario you described is generally called stream backup, where one stream is selected as the primary stream, and if it fails, it switches to the backup stream. It's quite complex because it requires resolving a set of problems, so you should not expect a simple answer for this. Let me try to illuminate this. The simplest solution is to use FFmpeg to pull from two streams and select one as the primary stream. You can do this with a very simple script. To select from streams ( for ((;;)); do
ffmpeg -i rtmp://localhost/live/streamA -c copy rtmp://localhost/live/livestream;
ffmpeg -i rtmp://localhost/live/streamB -c copy rtmp://localhost/live/livestream;
done Generally, you won't see any interruption because, for live streaming, there should be a period of cached frames in the player, such as a GOP of video frames around 10 seconds. Normally, the switching process should be smooth when the codec parameters are the same. The codec parameters include profile, preset, size, fps, and bitrate if you are using FFmpeg. As you mentioned, since you are using WebRTC, which will be converted to RTMP, it is difficult to keep the codec parameters the same. So, I recommend that you conduct some tests to verify this. However, you can use FFmpeg to transcode both streams to the same codec parameters. For example: for ((;;)); do
ffmpeg -i rtmp://localhost/live/streamA -c:v libx264 -profile:v baseline -preset fast -b:v 1m -r 25 -s 1024x768 -c:a copy rtmp://localhost/live/streamA2;
ffmpeg -i rtmp://localhost/live/streamB -c:v libx264 -profile:v baseline -preset fast -b:v 1m -r 25 -s 1024x768 -c:a copy rtmp://localhost/live/streamB2;
done After converting streamA to streamA2 and streamB to streamB2 using the same codec parameters, you can now switch between them smoothly. Note that transcoding will cause a bit delay because it also caches some frames, so you should change the transcoding parameters to low-latency configurations. Please refer to the FFmpeg manual. If you do not need to convert WebRTC to RTMP -- for example, if you only need to deliver a WebRTC stream -- then implementing the switcheroo in SRS may be a better solution. But this feature is not supported by SRS; you need to develop it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
Use case: I have two clients streaming WebRTC in the same room and I need to output a single RTMP push stream. I want to be able to use an API to switch the input from one WebRTC client to the other live without interrupting the RTMP stream and without a black screen while switching from one to the other.
Is it something that would be possible with SRS? How long would SRS need before it actually performs a switch from one WebRTC input to the other? Would the output RTMP push stream not be interrupted when doing the switch? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions