nginx+rtmp module搭建直播+录制环境

安装过程

 

1、将nginx和nginx-rtmp-module的源码包解压
PS:

nginx下载地址

http://nginx.org/en/download.html

nginx-rtmp-module网址
https://github.com/arut/nginx-rtmp-module

2、进入nginx的源代码目录,编译
./configure --add-module=<path-to-nginx-rtmp-module>

使用nginx 1.7.2

错误如下:

adding module in /home/andrew/Work/tools/nginx-rtmp-module

 + ngx_rtmp_module was configured

checking for PCRE library ... not found

checking for PCRE library in /usr/local/ ... not found

checking for PCRE library in /usr/include/pcre/ ... not found

checking for PCRE library in /usr/pkg/ ... not found

checking for PCRE library in /opt/local/ ... not found

 

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

需要安装PCRE或者不支持rewrite功能

./configure --add-module=<path-to-nginx-rtmp-module>  --without-http_rewrite_module
make
make install

3、写一个测试配置文件

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;
 
    sendfile        on;
    keepalive_timeout  65;
 
    server {
        listen       80;
        server_name  localhost;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        location /stat {
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
                root /home/andrew/Work/tools/nginx-rtmp-module;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
 
rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application myapp {
                        live on;
                }
        }
}

 

nginx配置

worker_processes  1;
user root;
#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;

    sendfile        on;
    keepalive_timeout  18000;

    server {
        listen       80;
        server_name  localhost;

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

            client_body_temp_path  /usr/local/nginx/html/tmp;
        }

	location /stat {
		rtmp_stat all;
		rtmp_stat_stylesheet stat.xsl;
	}
	location /stat.xsl {
		root /home/andrew/Work/tools/nginx-rtmp-module;
	}
	

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

rtmp {
	server {
		listen 1935;
		chunk_size 4096;
		application myapp {
			live on;
			record all;
			record_path /tmp/;

			recorder all {
				record all;
				record_suffix -%d-%b-%y-%T.flv;
			}
		}
	}
}

启动nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 

 进入/usr/local/nginx/sbin目录,执行nginx

./nginx  

 打开浏览器输入http://ip可看到nginx已经启动的画面

 

使用ffmpeg推流到服务器

例如

./ffmpeg -re -i test2.flv -c:a copy -y -f flv rtmp://192.168.40.128:1935/myapp/stream1

 

访问http://192.168.40.128/stat,看到以下统计信息

 

nginx结束

./nginx -s stop或者./nginx -s quit  

 

一个是强制快速结束,一个是温柔结束.

 

注释:

192.168.40.128为测试内网IP

转载于:https://my.oschina.net/u/2326611/blog/672245

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值