ubuntu nginx 搭建RTMP 流媒体直播

参考文章:

  1. http://www.voidcn.com/article/p-nldqeryg-vh.html
  2. http://www.voidcn.com/article/p-auinnbgb-xu.html
  3. https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04
  4. https://www.jianshu.com/p/f0bf83ca3ea3

将外面的流解码转发到自己的直播流接口

nohup ffmpeg -i "rtmp://rtmp01open.ys7.com/openlive/f01018a141094b7fa138b9d0b856507b.hd" -f flv -r 25 -s 640*640 -an "rtmp://localhost:2016/hls/demo"&

利用流文件生成m3u8文件

nohup ffmpeg -v verbose -i rtmp://localhost:2016/hls/demo -c libx264 -c:a aac -ac 1 -strict -2 -crf 20 -profile:v main -maxrate 800k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -start_number 1 -f segment -segment_list demo.m3u8 -segment_list_flags +live -segment_time 10 out%03d.ts&

nginx.conf配置文件:


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#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;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
    
    location /stat {        
                rtmp_stat all;  
                rtmp_stat_stylesheet stat.xsl;  
    }  
  
        location /stat.xsl {    
        root /usr/local/nginx/nginx-rtmp-module/;  
        }

    location /live {
            # 配置服务器访问路径
            types {  
                application/vnd.apple.mpegurl m3u8;  
                video/mp2t ts;  
            }
        alias /tmp/hls;
        expires -1;
            add_header Cache-Control no-cache;  
        add_header Access-Control-Allow-Origin *;   # 解决跨域请求问题
    }

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}


# 配置直播流服务
rtmp {  
    server {  
        listen 2016;  
        application hls {  
            live on;  
            hls on;  
            hls_path /tmp/hls; 
        hls_fragment 15s;

        }  
    }  
}

你可能感兴趣的:(ubuntu nginx 搭建RTMP 流媒体直播)