arut / nginx-rtmp-module

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

Use IF ELSE condition into RTMP #1204

Open friman opened 6 years ago

friman commented 6 years ago

Hi guys, Is there some way to condition application usage inside some rtmp application? For example, I need to do something like

***********************
application live {
      live on;
      if ($name ~"tv") {
            push rtmp://localhost/aux/;
      }
}

application aux {
   live on;
   hls on;
  ***********
}

Thanks in advance!

pierreyves258 commented 4 years ago

Hi, Does someone have an idea for this feature ? This would be very usefull !

Thanks

pierreyves258 commented 4 years ago

For those who keep looking for a solution these two

First:

exec_publish my_on_publish_command name=mystream;

will only execute if the stream key is 'mystream'

Second:

rtmp { 
...
    application1 {
        on_publish http://127.0.0.1:NGINX_HTTP_PORT/my_callback;
        notify_method get;
    }
...
}

http {
...
    location /my_callback {
        if($arg_name = 'mystream') {
            return 200;
        }
        return 403;
    }
...
}

The second one is more flexible, you cam have all those vars https://github.com/arut/nginx-rtmp-module/wiki/Directives#on_play one more if you stream to rtmp://server:port/app/key?var=value var will be accessible with $arg_var in http section