Skip to content

Control module

Gino Hu edited this page Jul 31, 2018 · 3 revisions

Control module is HTTP module which makes it possible to control rtmp module from outside using HTTP protocol. Here's an example of how to enable control.

http {
...
    service {
    ...
    server {
            listen       8080;
            server_name  localhost;
            ....
            location /control {
                rtmp_control all;
            }
        }
    }
}

There are several sub-modules within control module each controlling a different feature.

Record

This sub-module starts and stops recordings created with manual flag. Syntax:

http://server.com/control/record/start|stop?srv=SRV&svi=SVI&app=APP&name=NAME&rec=REC
  • srv=SRV - optional server{} block number within rtmp{} block, default to first server{} block
  • app=APP - required application name
  • name=NAME - required stream name
  • rec=REC - optional recorder name, defaults to root (unnamed) recorder

Example

rtmp {
    service {
        server {
            listen 1935;
            application myapp {
                live on;
                recorder rec1 {
                record all manual;
                record_suffix all.flv;
                record_path /tmp/rec;
                record_unique on;
            }
        }
    }
}

Publish the stream with the following command

ffmpeg -i http://someserver.com/mychannel.ts -c:v copy -c:a nellymoser -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream

Use the following commands to start and stop recording

curl "http://localhost:8080/control/record/start?svi=mysvi&app=myapp&name=mystream&rec=rec1"
curl "http://localhost:8080/control/record/stop?svi=mysvi&app=myapp&name=mystream&rec=rec1"

if the record start/stop request returns nothing sometimes, you should check if you use multi workers. one worker works great.

Drop

This sub-module provides a simple way to drop client connection. Syntax:

http://server.com/control/drop/publisher|subscriber|client?
srv=SRV&svi=SVI&app=APP&name=NAME&addr=ADDR&clientid=CLIENTID
  • srv, svi, app, name - the same as above
  • addr - optional client address (the same as returned by rtmp_stat)
  • clientid - optional nginx client id (displayed in log and stat)

The first method drop/publisher drops publisher connection. The second drop/client drops every connection matching addr argument or all clients (including publisher) if addr is not specified.

Examples

curl http://localhost:8080/control/drop/publisher?svi=mysvi&app=myapp&name=mystream
curl http://localhost:8080/control/drop/client?svi=mysvi&app=myapp&name=mystream
curl http://localhost:8080/control/drop/client?svi=mysvi&app=myapp&name=mystream&addr=192.168.0.1
curl http://localhost:8080/control/drop/client?svi=mysvi&app=myapp&name=mystream&clientid=1

Redirect

Redirect play/publish client to a new stream. Syntax:

http://server.com/control/redirect/publisher|subscriber|client?
srv=SRV&svi=SVI&app=APP&name=NAME&addr=ADDR&clientid=CLIENTID&newname=NEWNAME
  • srv, svi, app, name, addr, clients - the same as above
  • newname - new stream name to redirect to

Relay

Trigger push/pull relay stream from URL to a new destination. Syntax:

http://server.com/control/relay/push|pull?
src=SRC&dst=DST
  • src=SRC - relay source URL
  • dst=DST - destination of relay
Clone this wiki locally