Nginx 使用 rtmp 模块

该备忘配置参考于 搭建Nginx+nginx-rtmp-module的hls流媒体服务器并用OBS进行推流

Nginx 编译

首先 nginx 需要安装 rtmp 模块

1
2
3
4
cd /home/nginx
git clone https://github.com/arut/nginx-rtmp-module
./configure --prefix=/usr/local/nginx --add-module=/home/nginx/nginx-rtmp-module --with-http_ssl_module
make && make install

增加配置

vim /usr/local/nginx/conf/nginx.conf

与 http {} 同级

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
rtmp {
server {
listen 1935; # 监听端口
chunk_size 4096;
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 5s;
hls_playlist_length 15s;
hls_continuous on; # 连续模式。
hls_cleanup on; # 对多余的切片进行删除。
hls_nested on; # 嵌套模式。
}
}
}

启动 nginx

1
nginx -s reload

推流

常用的是 ffmpeg 或者各种开源软件,在 github 上搜一下推流

rtmp://ip:1935/hls[/name] 上推流即可

  • [/name] 指的可以不要这一块,也可以要。两者的区别就是在服务器中生成 m3u8 的地址不同,不填的时候就在 /tmp/hls,如果填了 /abc,则会生成在 /tmp/hls/abc

拿流

往拿推就往拿哪