Sei sulla pagina 1di 5

[ TUTURIAL SERVIDOR RTMP PARA FAZER STREAM EM VÁRIOS SITES COM NGINX E

FFMPEG ]

## PASSO 01 - BAIXAR AS FERREAMENTAS DE COMPILAÇÃO ##

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

-----------------------------------------------------------------------------------------------------

## PASSO 02 - BAIXAR O NGINX JUNTAMENTE COM O MÓDULO RTMP E FAZER A


DESCOMPACTAÇÃO DOS ARQUIVOS ##

wget http://nginx.org/download/nginx-1.12.2.tar.gz

wget https://github.com/arut/nginx-rtmp-module/archive/master.tar.gz

tar -xzvf nginx-1.12.2.tar.gz

tar -xzvf master.tar.gz

rm nginx-1.12.2.tar.gz

rm master.tar.gz

----------------------------------------------------------------------------------------------------

## PASSO 03 - COMPILAR O NGINX JUNTAMENTE COM O RTMP MODULE

cd nginx-1.12.2

./configure --with-http_ssl_module --without-http_gzip_module --add-module=../nginx-rtmp-


module-master

make

sudo make install

----------------------------------------------------------------------------------------------------

## PASSO 04 - CONFIGURAR O NGINX PARA INICIAR JUNTO COM O SISTEMA ##

sudo wget https://raw.githubusercontent.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O


/etc/init.d/nginx

sudo chmod +x /etc/init.d/nginx

sudo update-rc.d nginx defaults

---------------------------------------------------------------------------------------------------

## PASSO 05 - INSTALAR O FFMPEG E SUAS DEPENDÊNCIAS ##


sudo apt-get install software-properties-common

sudo apt-get install ffmpeg

---------------------------------------------------------------------------------------------------

## PASSO 06 - CONFIGURAR O NGINX

Abaixo temos um exemplo de configuração

user www-data;
worker_processes 1;

events {
worker_connections 1024;
}

# http requests allow checking that rtmp is working and being published to
http {

# turn off server tokens and hide what server version you are using
server_tokens off;

include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
listen 80;
server_name localhost;

error_log /var/log/nginx_error.log warn;

# allows you to view stats


location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}

# allow stat xml styling to be accessed


location /stat.xsl {
root html;
}

# make a internal server page and put it in html


error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

# rtmp server configuration


rtmp {
server {
# port to listen on, I've left this as a default
listen 1935;
chunk_size 8192;

# this is what you will stream to


application live {
live on;

# record off means no vod saving


record off;

# allow publishing from all (change this to your ip if you wish to lock to ip address)
allow publish all;

# uncomment this if you are going to deny every ip other than yours
# deny publish all;

# push to all sub applications we will create (one each for each application)
push rtmp://localhost/youtube;
push rtmp://localhost/facebook;
push rtmp://localhost/mixer;

# for twitch I'm being more specific so I can define how my stream looks on twitch
exec ffmpeg -i rtmp://localhost/$app/$name -c:v libx264 -preset veryfast -c:a copy
-b:v 3500k
-bufsize 3500k
-maxrate 3500k
-s 1280x720 -r 30
-f flv rtmp://localhost/twitch/$name;
}

# example youtube app


application youtube {
live on;
record off;

# only allow this machine to publish


allow publish 127.0.0.1;
deny publish all;

# push url, this will be your stream url and stream key together
push rtmp://{youtube-stream-url};
}

# example twitch app


application twitch {
live on;
record off;

# only allow this machine to publish


allow publish 127.0.0.1;
deny publish all;

# push url, this will be your stream url and stream key together
push rtmp://{twitch-stream-url};
}
application facebook {
live on;
record off;

allow publish 127.0.0.1;


deny publish all;

# push url, this will be your stream url and stream key together
push rtmp://{facebook-stream-url};

application mixer {
live on;
record off;

# only allow this machine to publish


allow publish 127.0.0.1;
deny publish all;

# push url, this will be your stream url and stream key together
push rtmp://{mixer-stream-url};
}
}
}

-Mudando as permissões da pasta

chown -R www-data:www-data /usr/local/nginx/html

-Reiniciando o nginx

service nginx restart

---------------------------------------------------------------------------------------------------

## PASSO 07 - CONFIGURAR O FFMPEG ##

Abaixo tem um exemplo de configuração boa pra usar no youtube.

ffmpeg -i [entrada] -b:v 3M -b:a 128k -vcodec libx264 -pix_fmt yuv420p -acodec copy -ar 44100 -s
1280x720 -preset ultrafast -framerate 30 -g 60 -f flv [ponto de saida]
---------------------------------------------------------------------------------------------------

## PASSO 08 - USAR O OBS ##

Para transmitir para varios sites basta configurar o exemplo do PASSO 06 com as chaves de cada
sistema e manda o obs entregar os fluxos no ponto rtmp://ip/live lembrando que o servidor precisa
permitir entrada na porta do rtmp que por padrão é 1935

---------------------------------------------------------------------------------------------------

Potrebbero piacerti anche