nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择。本文介绍了一种简易方法快速搭建rtmp流媒体服务器,也 叫rtsp转播,数据源不是读取文件,而是采用获取rtspNal流后使用ffmpeg转播。csdn固本培元:leoluopy@gmail.com
开发环境:centos6.4 (主流的linux服务器选择,30%以上的市场占有率)
需要这几个包。
版本号:nginx 1.7.3 openssl 1.0.2 rtmp-module(版本未知)
资源:这些都是公网下载的资源,有需要的朋友,可以给我email或者评论留言。email:leoluopy@gmail.com
注意:先编译openssl 然后编译nginx
编译选项:
./configure --add-module=../nginx-rtmp-module-master --without-http_rewrite_module --with-openssl=../openssl-1.0.2-beta2
./configure --add-module=../nginx-rtmp-module-master --without-http_rewrite_module --with-openssl=../openssl-1.0.2-beta2
一路通过
启动时可能出现错误:
Starting nginx: nginx: [emerg] unknown directive "rtmp" in /etc/nginx/nginx.conf:9
Starting nginx: nginx: [emerg] unknown directive "rtmp" in /etc/nginx/nginx.conf:9
没有识别rtmp模块。
另外一种可能,原有centos从源安装了nginx,它不带rtmp模块,需要卸载。
安装编译好的nginx后:
进入:
/usr/local/nginx/sbin
./nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin
./nginx -c /usr/local/nginx/conf/nginx.conf
(注意:后面的需要是绝对地址)
ffmpeg推流 (如果没有flv文件,可以用264,ts这些文件转换,ffmpeg的常用命令本博客另一篇文章也有简要介绍)
ffmpeg -re -i IpCam.flv -f flv rtmp://localhost/myapp/test1
ffmpeg -re -i IpCam.flv -f flv -b 20000000 rtmp://localhost/myapp/test1
ffmpeg -re -i IpCam.flv -f flv rtmp://localhost/myapp/test1
ffmpeg -re -i IpCam.flv -f flv -b 20000000 rtmp://localhost/myapp/test1
实时rtsp转rtmp直播流(其实转了rtmp之后会多几秒钟的延迟,不同客户端还不一定一致,我们这里测试的是JWplayer 3秒左右(后面用了个flex的方案,时间延迟提升到2s),稳定时可以在1秒左右,vlc播放器更长了10秒 ~_~! ,客户端的话还是就用rtsp吧,这样很快,一般延迟可以忽略不计