Search code examples
phpnginxrtmp

Pushing RTMP Stream to multiple dynamic destination


I have a application that works like a RTMP proxy server.

rtmp {
    server{
         listen 1935;
         chunk_size 4096;
    
         application live {
             live on;
             record off;
        
             push rtmp://server1/live/{key1}
             push rtmp://server2/live/{key2}
         }
    }
}

The key1 and key2 coming from a PHP file. How can i replace keys from PHP file to nginx config file ?


Solution

  • To process the stream, it's a powerful pattern to use FFmpeg to pull and push as different streams:

    ffmpeg -f flv -i rtmp://localhost:1935/app/bbbb \
      -c copy -f flv rtmp://localhost:1935/app/aaaaaa \
      -c copy -f flv rtmp://localhost:1935/app/cccccc
    

    Note: You could use the on_publish hook to start your FFmpeg process, or exec should also works. However it's a bit complex for introducing FFmpeg.

    If you want to use push feature, it's a complex and dynamic forwarding, I think it's very hard to support it because it depends on our use scenarios, which is very different and not common to everyone.

    Note: However, I think the best solution is like http hooks forwarding, that is call your backend and get the streams to forward to. Here is a discuss about dynamic forwarding by http hooks.