MorpheusXAUT
MorpheusXAUT

Reputation: 31

Switch between multiple stream inputs with nginx rtmp

two colleagues of mine recently started streaming to Twitch together and wanted to create a setup where they could switch between their streams "live" (e.g. A is streaming, wants to end, B starts his stream and there is no interruption). Twitch obviously only allows one person at a time to stream to a specific channel/stream key and stopping one stream & instantly starting the other one usually results in ~ 10 seconds "downtime".

For this reason, I looked into setting up a server they can both stream to which can handle two inputs and push out one single stream to the Twitch ingest servers. I checked a few tutorials about setting up nginx and the rtmp addon for this purpose, however am running into the same issue of only one person being able to stream at a time. One possibility I figured would be to get a client streaming program like OBS or XSplit set up on the server which then displays streams from both nginx-rtmp inputs and switches scenes as needed, however both programs seem to require a graphics card for their live "preview" and thus don't work on my server.

Is there any nginx-rtmp config or other clientside (optimally linux, but can be windows as well) solution I could use for combining two input RTMP streams into a single output stream? Switching between inputs can be done via hand as well if needed, as long as it works "live" and without interruption of the output.

Thanks in advance!

Upvotes: 3

Views: 8119

Answers (1)

aergistal
aergistal

Reputation: 31209

This is what I did with ffmpeg and YouTube Live Events which also uses an RTMP input. Might work with Twitch too:

  • pull the two streams to your server, one at a time, and push them in an intermediary format like mpegts to a local UDP port. In my case it's already H.264/AAC:

    ffmpeg -re -i <source1> -c copy -bsf:v h264_mp4toannexb udp://127.0.0.1:10000
    

    then kill and do immediately:

    ffmpeg -re -i <source2> -c copy -bsf:v h264_mp4toannexb udp://127.0.0.1:10000  
    
  • fetch the local stream, encode and push it via RTMP. It'll wait if there's no input and will manage the discontinuities in PTS/DTS:

    ffmpeg -re -i udp://127.0.0.1:10000 -c:v libx264 -r 25 -g 100 -c:a libfdk_aac -f flv rtmp://...
    

Upvotes: 2

Related Questions