目前,nginx-rtmp-module是主流的直播软件解决方案,基于nginx开发的一个扩展模块。
1、下载nginx-rtmp-module模块
git clone https://github.com/arut/nginx-rtmp-module.git
2、安装nginx并加上nginx-rtmp-module模块
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
make && make install
如果报错
checking for PCRE library ... found
checking for PCRE JIT support ... not found
checking for OpenSSL library ... not found
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
可能你没装openssl,
centos的话yum -y install openssl openssl-devel 然后./configure
Ubuntu的话sudo apt-get install libssl-dev
其他unix的话直接下载源码https://www.openssl.org/,然后./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-openssl=../openssl安装路径/openssl.1.0.2*
3、配置nginx.conf
创建nginx.conf文件,写入下面内容
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 5s;
}
}
}
http {
server {
listen 8080;
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
expires -1;
}
}
}
然后将指定改文件为nginx的配置文件
/usr/local/bin/nginx -c /etc/nginx/nginx.conf -s reload
4、推流和拉流
然后开始rtmp推流rtmp://39.27.10.138/hls/CfFgTbUr6Lok23aY,可以使用OBS推流工具
然后查看/tmp/hls目录就会发现产生了很多ts文件和一个m3u8文件
接下来使用VLC进行拉流,rtmp://39.27.10.138/hls/CfFgTbUr6Lok23aY是rtmp协议的直播流,你在推的时候才能拉,特点是延迟低,并且只有在推流的时候才能拉。http://39.27.10.138:8080/hls/CfFgTbUr6Lok23aY.m3u8是hls流
网友评论