参考
nginx-rtmp-module
How to set up your own private RTMP server using nginx
原料
- nginx
- ngnix-rtmp-module
- homebrew
- open Boardcaster software
步骤
安装homebrew
#安装脚本
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装完成后使用brew 安装nginx 和 nginx-rtmp-module
brew install nginx-full --with-rtmp-module
测试nginx
nginx 简单操作命令
- nginx 启动服务器
- nginx -s stop 关闭服务器
启动服务器后 使用浏览器打开地址http://localhost:8080
出现上面的界面说明 nginx 搭建成功
配置nginx
打开文件 /usr/local/etc/nginx/nginx.conf
在文件末尾添加如下配置
rtmp {
server {
listen 1935;
chunk_size 4096;
application hls {
live on;
}
}
}
然后重启服务器
启动OBS 配置stream
- 打开setting>Stream Stream type 选择 custom stream server
- url 设置 rtmp://<ip>:<端口>/hls
- 设置 stream key
- 点击 start streaming
使用浏览器打开网页
server 输入你的server 地址 stream 输入你的 stream key
支持 HLS (HTTP Live Streamming)
修改nginx.conf
rtmp {
server {
listen 1935;
chunk_size 4000;
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 5s;
}
}
}
# HTTP can be used for accessing RTMP stats
http {
server {
listen 8080;
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
}
}
测试HLS
用 safari 打开网页 选择Apple HLS
输入地址 http://192.168.31.239:8080/hls/mystream.m3u8