rtmp_relay icon indicating copy to clipboard operation
rtmp_relay copied to clipboard

Multiple streams over a singel connection

Open ReubenM opened this issue 9 years ago • 6 comments

How hard would this be to modify a bit to support multiple streams over a single connection? I've been looking for a relay like this, but haven't found one that can ingest multiple inputs from separate connections, and push them out to remote locations, but all over a single connection with each remote location. Everything I've been able to find creates a new connection for each stream.

ReubenM avatar Nov 16 '16 04:11 ReubenM

Could you please explain this a bit more? What do you mean by multiple streams over single connection?

elnormous avatar Nov 21 '16 01:11 elnormous

A "connection" is the session that is negotiated between client and server. It is possible to do a createStream and publish multiple streams all within the same connection. Most solutions just make multiple connections if they need to publish multiple streams to that same server.

You can test it with Adobe's free Live Encoder by setting it to encode multiple bitrates. Point it to your server, and set the "stream"field in the encoder to "%i". (Which tells it to name each stream by it's index value)

So if you set it to encode 3 bitrates and publish to rtmp://myserver.tld/myApp/, there will be streams published to that app by names "1" "2" and "3", but they will all be getting published over the same connection. The packets of the separate streams are all multiplexed together.

ReubenM avatar Nov 21 '16 04:11 ReubenM

Is there any specification for this behavior? How does the server know which channel belongs to which stream? This would involve a slight change in the configuration, but it is not impossible, I just have to understand how to notify the server about the stream's channels.

elnormous avatar Nov 22 '16 13:11 elnormous

What happens is that there is more than one createStream + publish. If I understand the documentation correctly, each new createStream + publish creates a new message stream ID, The audio and video chunks are tagged with their respective message stream IDs.

The leading Type 0 chunk in a chunk stream contains a 4 byte little edian ID number in the header that identifies it's media stream ID.

ReubenM avatar Nov 23 '16 04:11 ReubenM

Oh, ok. I see that I am using the messageStreamId field of the RTMP header incorrectly. Ok, then there is no problem to implement it the way you ask.

elnormous avatar Nov 23 '16 13:11 elnormous

Well, again that is assuming I understand the documentation correctly. The spec that adobe provides is very terse and inexplicit.

ReubenM avatar Nov 23 '16 13:11 ReubenM