Nginx-rtmp-module

De MochilaWiki
Ir para navegaçãoIr para pesquisar

compilando nginx com módulo rtmp

apt-get install libgd2-noxpm build-essential devscripts ffmpeg debian-keyring
apt-get build-dep nginx
apt-get source nginx
dpkg-source -x nginx_1.2.1-2.2+wheezy2.dsc
wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.2.tar.gz
tar xvzf v1.1.2.tar.gz
mkdir nginx-1.2.1/debian/modules/nginx-rtmp-module
cp -r nginx-rtmp-module-1.1.2/*  nginx-1.2.1/debian/modules/nginx-rtmp-module

em nginx-1.2.1/debian/rules abaixo de

--add-module=$(MODULESDIR)/nginx-dav-ext-module \ 

coloque

--add-module=$(MODULESDIR)/nginx-rtmp-module \

em nginx-1.2.1/debian/source/include-binaries acrescente

debian/modules/nginx-rtmp-module/test/rtmp-publisher/RtmpPlayer.swf
debian/modules/nginx-rtmp-module/test/rtmp-publisher/RtmpPublisher.swf
debian/modules/nginx-rtmp-module/test/rtmp-publisher/RtmpPlayerLight.swf
debian/modules/nginx-rtmp-module/test/www/bg.jpg
debian/modules/nginx-rtmp-module/test/www/jwplayer_old/player.swf
debian/modules/nginx-rtmp-module/test/www/jwplayer/jwplayer.flash.swf

e depois

cd nginx-1.2.1/
dpkg-buildpackage -rfakeroot -b
cd /usr/src/
dpkg -i nginx-full_*.deb nginx-common_*.deb

configuração do nginx com rtmp e hls

altere em /etc/nginx/nginx.conf

worker_processes  2;
events {
    worker_connections  1024;
}
http {
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        # in case we have another web server on port 80
        listen       8080;
        location /hls {
          types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
          }
          #where the m3u8 and ts files are
  #        alias /var/www/hls;
          alias /tmp;
        }
        location / {
            # here we can put our website
            root   /var/www/html;
            index  index.html index.htm;
        }
    }
}

rtmp {
    server {
#        listen 1935;
         listen 80;

        application src {
            live on;

            exec ffmpeg -i rtmp://localhost/src/$name
              -c:a libfdk_aac -b:a 32k  -c:v libx264 -b:v 128K -f flv rtmp://localhost/hls/$name_low
              -c:a libfdk_aac -b:a 64k  -c:v libx264 -b:v 256k -f flv rtmp://localhost/hls/$name_mid
              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -f flv rtmp://localhost/hls/$name_hi;
        }

        application hls {
            live on;

            hls on;
            hls_path /tmp/hls;
            hls_nested on;

            hls_variant _low BANDWIDTH=160000;
            hls_variant _mid BANDWIDTH=320000;
            hls_variant _hi  BANDWIDTH=640000;
        }
    }
}

teste de envio com ffmpeg

ffmpeg -i video-teste.mp4 -c:a copy -c:v copy -f flv rtmp://127.0.0.1/src/sintel

assistindo com ffplay

ffplay rtmp://127.0.0.1/src/sintel