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

relay two RTMP streams, each to its own destination? #1538

Open jacobevans opened 4 years ago

jacobevans commented 4 years ago

I'm trying to setup a server that can proxy two different rtmp streams, each to it's own destination. I also want to create recordings of both streams. See the config below:

worker_processes  1;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;

            record all;
            record_path /recordings;
            record_suffix -%d-%b-%y-%T.flv;
            record_lock on;
            record_interval 15m;

            push rtmp://a.rtmp.youtube.com/live2/[STREAM KEY];
        }
        application live2 {
            live on;
            record all;

            record_path /recordings;
            record_suffix -%d-%b-%y-%T.flv;
            record_lock on;
            record_interval 15m;

            push rtmp://a.rtmp.youtube.com/live2/[DIFFERENTKEY];
        }
    }
}

I then connect one encoder to rtmp://domain/live/cam1 and the other to rtmp://domain/live2/cam2

It works for recordings. I get separate recorded flv files for each input.

However, for the output push stream, both stream keys get whichever input stream connected first. So, for example, if my cam1 encoder connects to my nginx server a few seconds before cam2, both youtube encoders see the output of that encoder, even though I get both recordings.

Am I doing something wrong here? Am I not understanding how nginx-rtmp is supposed to work?

I have tried creating two entirely separate server blocks (each on its own port), and it has the same result!

I've also tried using the name parameter in the push directive, and that doesn't seem to do anything either (though perhaps I did this wrong).

kitobelix commented 4 years ago

Try this, and then tell me how it goes.

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            push rtmp://a.rtmp.youtube.com/live2/[STREAM KEY] live=1;

            record all;
            record_path /recordings/live1;
            record_suffix -%d-%b-%y-%T.flv;
            record_lock on;
            record_interval 15m;

        }
        application live2 {
            live on;
            record all;
            push rtmp://a.rtmp.youtube.com/live2/[DIFFERENTKEY] live=1;

            record_path /recordings/live2;
            record_suffix -%d-%b-%y-%T.flv;
            record_lock on;
            record_interval 15m;

        }
    }
}