前言
利用开源的nginx-rtmp-module
和Nginx
搭建流媒体服务器。Nginx
是一个非常出色的http
服务器,nginx-rtmp-module
是一个开源的Nginx
扩展模块,拥有很多功能特性,像接收rtmp
推流拉流,hls
直播等:
1.RTMP/HLS/MPEG-DASH live streaming
2.RTMP Video on demand FLV/MP4, playing from local filesystem or HTTP
3.Stream relay support for distributed streaming: push & pull models
4.Recording streams in multiple FLVs
5.H264/AAC support
6.Online transcoding with FFmpeg
7.HTTP callbacks (publish/play/record/update etc)
8.Running external programs on certain events (exec)
9.HTTP control module for recording audio/video and dropping clients
10.Advanced buffering techniques to keep memory allocations at a minimum level for faster streaming and low memory footprint
11.Proved to work with Wirecast, FMS, Wowza, JWPlayer, FlowPlayer, StrobeMediaPlayback, ffmpeg, avconv, rtmpdump, flvstreamer and many more
12.Statistics in XML/XSL in machine- & human- readable form
13.Linux/FreeBSD/MacOS/Windows
下面是配置安装使用详细过程
1.下载nginx
nginx
官方下载地址:https://nginx.org/en/download.html1
wget https://nginx.org/download/nginx-1.13.8.tar.gz
2.解压
1 | tar -zxvf nginx-1.13.8.tar.gz |
3.下载nginx的扩展模块 nginx-rtmp-module
用于接收rtmp
推流,搭建流媒体服务器
源码地址:https://github.com/arut/nginx-rtmp-module1
git clone https://github.com/arut/nginx-rtmp-module
4.安装些必要的插件库
1 | apt-get install libpcre3 libpcre3-dev -y |
5.配置安装 nginx-rtmp-module
进入nginx源码,配置扩展nginx-rtmp-module模块,编译安装,下面的/home/hx/Downloads/nginx-rtmp-module 是 nginx-rtmp-module的下载目录。
1 | cd nginx-1.13.8 |
6.配置RTMP及启动nginx
安装完后会显示安装目录,一般安装在/usr/local/nginx
更多配置请参考https://github.com/arut/nginx-rtmp-module/wiki/Directives
设置nginx.conf文件加入rtmp配置
1 vim /usr/local/nginx/conf/nginx.conf
加入以下内容,更详细的配置见模块的官网1
2
3
4
5
6
7
8
9
10rtmp_auto_push on;
rtmp {
server {
listen 1935;
application mytv {
live on;
}
}
}
启动
1 | cd usr/local/nginx/sbin |
停止nginx服务
查看进程信息包括id
1 | ps -ef |grep "nginx" |
杀死进程
1 | kill -9 id |