通過nginx,nginx-rtmp-module實現流媒體直播
1、
下載nginx
http://nginx.org/en/download.html
下載nginx-rtmp-module:
nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module
2、安裝nginx
- yum -y install openssl openssl-devel
- cd nginx-1.15.0
- ./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_module
- make && make install
3、修改nginx配置檔案:加入下面內容
rtmp {
server {
listen 1935; #監聽的埠
chunk_size 4000;
application hls { #rtmp推流請求路徑
live on;
hls on;
hls_path /usr/share/nginx/html/hls;
hls_fragment 5s;
}
}
}
修改server
server {
listen 8086;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
root /usr/share/nginx/html;
index index.html index.htm;
}
hls_path需要可讀可寫的許可權,因為/usr/share/nginx/html/hls在目錄中還沒有,所以使用以下命令建立目錄
mkdir -p /usr/share/nginx/html/hls
sudo chmod -R 777 /usr/share/nginx/html/hls
啟動nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
4、下載obs https://obsproject.com/download
然後設定,檔案》設定
填寫完,選擇應用。然後開始推流。
在/usr/share/nginx/html/hls會生成test.m3u8
5、在手機瀏覽器訪問
ip:8086/hls/test.m3u8