arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.36k stars 3.51k forks source link

RTMP push dynamic hostname resolution support? #1356

Open NamoDev opened 5 years ago

NamoDev commented 5 years ago

So I'm trying to build a "stream forking" server with this module. Already got the basics up and running, but now I'm running into a new problem. Here's a part of my config that handles forking:

rtmp {
    server {
        ...
        application fork {
            ...
            push rtmp://endpoint.example.com/live/streamkey;
            push rtmp://stream.test.com/live/streamkey;
        }
    }
}

Based on my (limited) knowledge of nginx and how this module works, it seems that the RTMP module resolves the RTMP server's hostname (i.e. endpoint.example.com) during config check or reload. Now this causes some issues - ideally, I'd want to be able to configure/restart my instance while it's offline (therefore no hostname resolution), then have the module dynamically resolve said hostname when the stream is started.

All in all, I'd like to be able to do this (or other things that achieves the same effect), so that each time the stream is started, nginx will dynamically resolve the RTMP server hostname(s):

rtmp {
    server {
        ...
        application fork {
            ...
            resolver 9.9.9.9;
            set $rtmp_endpoint rtmp://endpoint.example.com/live/streamkey;
            set $rtmp_endpoint2 rtmp://stream.test.com/live/streamkey;
            push $rtmp_endpoint;
            push $rtmp_endpoint2;
        }
    }
}

From what I see with issue #766, this is something that is not currently possible. So, are there any plans to add this feature to nginx-rtmp? Or are there other ways to achieve this? Other issues I see around mentioned the on_publish hook, but could that be used to "fork" the stream out to 2 or more RTMP servers?

Thanks!

misiek08 commented 5 years ago

One "hack" I can think of is configuring locally another application called "output", setting on_publish there and the script would dynamically resolve and redirect output streams.