Skip to content

How to handle new services

Noxalus edited this page Mar 20, 2018 · 3 revisions

By default, this project provide a template with examples for Youtube, Twitch, Dailymotion and Hitbox live services, but you might want to broadcast to another one like Facebook Live for instance.

Of course, it's possible, all you need to retrieve is the RTMP URL of the service in addition with your personal stream key generated by this service.

For Facebook Live, here is what it looks like:

(Please make sure to pick the checkbox to make the stream key persistent otherwise you will need to change the Nginx configuration each time you make a new live stream...)

Now, look at the file called nginx/conf/nginx.template.conf, specifically to the rtmp block:

This file has a really simple structure easily understandable thanks to the image above. The red block corresponds to the live application, the one on which you will send your video stream with the following URL rtmp://yourdomain:1935/live. It's into this application that you will transmit the video stream to all services you want. These services are described by the blue blocks that simply push the stream to the RTMP URL corresponding to each service.

If we want to handle Facebook live, we need to add a new application block. Let's call this application facebook:

application facebook {
	live on;
	record off;

	allow publish 127.0.0.1;
	deny publish all;

	push rtmp://live-api-a.facebook.com:80/rtmp/151958038809828?s_ps=1&a=ATj_CJYL2PqKwBP4;
}

Note that we append the stream key to the RTMP URL, it's always like that.

Now, we just have to update the live application to push the video stream to our new facebook application

application live {
	[...]

	push rtmp://localhost/facebook/${name};
}

That's all, the Nginx configuration should be reloaded automatically with your changes.

Here is an entire Nginx configuration file that only broadcast your stream to Facebook live:

#user  nobody;
worker_processes  1;
 
error_log  logs/error.log  debug;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
pid        logs/nginx.pid;

 
events {
    worker_connections  1024;
}

http {
    include             mime.types;
    default_type        application/octet-stream;

    sendfile            on;
    keepalive_timeout   65;

    server {
        listen          8080;
        server_name     localhost;

        # rtmp stat
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            # you can move stat.xsl to a different location
            root html;
        }

        # rtmp control
        location /control {
            rtmp_control all;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
 
rtmp {
    server {
        listen 1935;
        chunk_size 8192;

        application live {
            live on;
            record off;
            
            allow publish {{ my_ip_address }};
            deny publish all;
			
            push rtmp://localhost/facebook/${name};
        }

		application facebook {
			live on;
			record off;

			allow publish 127.0.0.1;
			deny publish all;

			push rtmp://live-api-a.facebook.com:80/rtmp/151958038809828?s_ps=1&a=ATj_CJYL2PqKwBP4;
		}
    }
}
Clone this wiki locally