环境为:Linux Cent OS 6.9
先要配置一下编译环境
yum install -y gcc gcc-c++ autoconf wget
yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*
然后
cd /usr/local
下载nginx
然后 wget http://nginx.org/download/nginx-1.12.1.tar.gz
下载nginx-rtmp-module
然后 http://arut.github.com/nginx-rtmp-module/
通过xftp上传
然后解压这两个文件
tar -zxvf nginx-1.12.1.tar.gz
nginx-rtmp-module的文件名太长了 修改文件名为nrm
tar -zxvf nrm.tar.gz
解压完再修改一次为nrm
cd nginx-1.12.1
输入
./configure
然后
make
然后
make install
这样会看到 /usr/local 下有个nginx的目录就是默认的安装目录了
cd /usr/local/nginx/sbin
./nginx -s start 可能已经开启了
然后在任意浏览器输入 我的ip 就会出现nginx欢迎页
说明安装成功
接着加入nrm
cd /usr/local/nginx-1.12.1
上面已经配置了环境了 不需要额外再编译 openssl zlib等了 直接搞
./configure --add-module=/usr/local/nrm --prefix=/usr/local/nginx --with-debug
make
make install
就好了
然后测试一下推流
这里抄一下其他教程的代码
mkdir /usr/local/m3u8File
vim /usr/local/nginx/conf/nginx.conf
代码如下
worker_processes 1;
events { worker_connections 1024; }
rtmp { server{ listen 1935; application mylive{ live on; hls on; hls_path /usr/local/m3u8File; } } }
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 /mylive_hls{ types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } alias /usr/local/m3u8File; add_header Cache-Control no-cache; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
直接复制黏贴就好
cd /usr/local/nginx/sbin
./nginx -s reload
然后下载obs 或用 ffmpeg等推流测试
obs软件推流 rtmp://xx.xx.xx.xx:1935/mylive (错误举例 rtmp://xx.xx.xx.xx:1935/mylive/2)服务选自定义 流密钥随便写
ffmpeg 命令推流 ffmpeg -i /Users/zwt/Desktop/2.mp4 -c copy -f flv rtmp://xx.xx.xx.xx:1935/mylive
然后 cd /usr/local/m3u8File
ls
就能看到视频文件了
使用obs实时推流然后使用ffmpeg拉流
拉流代码 ffplay "rtmp://xx.xx.xx.xx:1935/mylive/111 live=1" 或访问hls为 ffplay http://xx.xx.xx.xx:80/mylive_hls/111.m3u8
live=1为标记实时观看 111为流的名称 |