您的位置:首页 > 运维架构 > Nginx

Ubuntu12.04.3 配置nginx-rtmp支持HLS

2014-02-17 21:20 239 查看
之前编译配置过 ngix-rtmp 来支持HLS.

linux和windows都有。 /article/3669219.html

今天需要测试下HLS,捣鼓了下http 服务器,发送HFS有问题啊,经常不重启不能工作。

于是换用linux下的nginx-rtmp。

发现需要重新配置下,才能让nginx-rtmp工作。

nginx-rtmp 的可执行文件的路径:



sbin中是带有rtmp模块的nginx 。

conf中是配置文件。

./nginx 就可以启动nginx,没有任何输出。

之前不知道,还以为是其他的服务器占用了这个端口呢:

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin# ./nginx

nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)

nginx: [emerg] still could not bind()

寻找80端口:

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin# sudo netstat -pan | grep ":80"tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      6048/nginx      tcp        1      0 192.168.1.88:47676      91.189.94.25:80         CLOSE_WAIT  2805/ubuntu-geoip-ptcp6       0      0 :::80                   :::*                    LISTEN      1343/apache2    

发现就是nginx占用了8080.
apache2应该用的是80

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin# ./nginx -hnginx version: nginx/1.4.3Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /home/zhangbin/streaming/hls/nginx-rtmp/home/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file修改 以下的hls_path:

application hls {
             live on;
             hls on;
             #hls_path /srv/nginxhls/app;
	     hls_path /home/zhangbin/alex/Downloads/testVideos;
             hls_fragment 5s;

       }


路径 /hls是指在浏览器或者播放器的 url中加入/hls,这里alias是定向到磁盘的实际路径。

location /hls {
           #server hls fragments
           types{
             application/vnd.apple.mpegurl m3u8;
             video/mp2t ts;
           }
        alias /home/zhangbin/alex/Downloads/testVideos;
        #/srv/nginxhls/app;
        expires -1;
        }


修改后有俩错误,主要是没有加上;导致的:

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin# ./nginx -s reload

nginx: [emerg] invalid number of arguments in "hls_path" directive in /home/zhangbin/streaming/hls/nginx-rtmp/home/conf/nginx.conf:40

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin#

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin#

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin# ./nginx -s reload

nginx: [emerg] invalid number of arguments in "alias" directive in /home/zhangbin/streaming/hls/nginx-rtmp/home/conf/nginx.conf:88

我最后的配置文件:

#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;
}

rtmp {
    server {
        listen 1935;

        application myapp {
            live on;

            #record keyframes;
            #record_path /tmp;
            #record_max_size 128K;
            #record_interval 30s;
            #record_suffix .this.is.flv;

            #on_publish http://localhost:8080/publish;             #on_play http://localhost:8080/play;             #on_record_done http://localhost:8080/record_done; 
       }
       application hls {
             live on;
             hls on;
             #hls_path /srv/nginxhls/app;
	     hls_path /home/zhangbin/alex/Downloads/testVideos;
             hls_fragment 5s;

       }
    }
}

http {
    server {
        listen      8080;

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

        location /stat.xsl {
            root <path-to-nginx-rtmp-module>;
        }

        location /control {
            rtmp_control all;
        }

        #location /publish {
        #    return 201;
        #}

        #location /play {
        #    return 202;
        #}

        #location /record_done {
        #    return 203;
        #}

        location /rtmp-publisher {
            root <path-to-nginx-rtmp-module>/test;
        }

        location /hls {
           #server hls fragments
           types{
             application/vnd.apple.mpegurl m3u8;
             video/mp2t ts;
           }
        alias /home/zhangbin/alex/Downloads/testVideos;
        #/srv/nginxhls/app;
        expires -1;
        }

        location / {
            root <path-to-nginx-rtmp-module>/test/rtmp-publisher;
        }

    }
}


重启:

root@Ubuntu32:/home/zhangbin/streaming/hls/nginx-rtmp/home/sbin#./nginx -s reload

浏览器并不直接支持m3u8和MP4:



用播放器吧:




                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐