轉(zhuǎn)自https://blog.csdn.net/kingroc/article/details/50839994,略有修改
開發(fā)環(huán)境:
CentOS7
Nginx 1.14.2
nginx-rtmp-module
Nginx服務(wù)器的搭建
前面部分參考http://www.reibang.com/p/fe7e06fb574c
- 配置并編譯nginx
使用nginx的默認(rèn)配置列荔,添加nginx的rtmp模塊
./configure --add-module=../nginx-rtmp-module-master
make
make install
- 測(cè)試nginx能否運(yùn)行
輸入/usr/local/nginx/sbin/nginx
敬尺,回車
打開瀏覽器,輸入服務(wù)器地址贴浙,如果如下圖則nginx運(yùn)行成功
點(diǎn)播視頻服務(wù)器的配置(RTMP)
- 編輯nginx的配置文件砂吞,配置RTMP
worker_processes 1;
events {
worker_connections 1024;
}
rtmp { #RTMP服務(wù)
server {
listen 1935; #//服務(wù)端口
chunk_size 4096; #//數(shù)據(jù)傳輸塊的大小
application vod {
play /home/video; #//視頻文件存放位置。
}
}
}
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
在/home/video文件夾中放入視頻文件崎溃,我放入了一個(gè)music.mp4
重新啟動(dòng)一下nginx蜻直,/usr/local/nginx/sbin/nginx -s reload
注意,如果服務(wù)器是配置在阿里云上的話,要在安全組配置中把RTMP端口號(hào)1935配置好概而,否則無(wú)法播放呼巷。這里其實(shí)就是注意防火墻端口配置問題
打開視頻播放軟件(這里使用VLC播放器),菜單中選擇“媒體”赎瑰,然后選擇“打開網(wǎng)絡(luò)串流”輸入點(diǎn)播地址rtmp://localhost/vod/music.mp4
如果成功則如下圖會(huì)播放相應(yīng)視頻王悍。
直播視頻服務(wù)器的配置
接著我們就在點(diǎn)播服務(wù)器配置文件的基礎(chǔ)之上添加直播服務(wù)器的配置。一共2個(gè)位置
- 第一處就是給RTMP服務(wù)添加一個(gè)application這個(gè)名字可以任意起乡范,也可以起多個(gè)名字,由于是直播我就叫做它live吧啤咽,如果打算弄多個(gè)頻道的直播就可以live_cctv1晋辆、live_cctv2名字任意。
- 第二處就是添加兩個(gè)location字段宇整,字段的內(nèi)容請(qǐng)直接看文件吧瓶佳。
worker_processes 1;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 4096;
application vod {
play /home/video;
}
application live{ #第一處添加的直播字段
live on;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location /stat { #第二處添加的location字段。
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl { #第二處添加的location字段鳞青。
root /usr/local/nginx/nginx-rtmp-module/;# 你的rtmp模塊所在文件夾
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
添加完后重啟nginx打開http://localhost/stat,會(huì)有下圖所示
配置obs,
-
添加媒體源霸饲,填入本地相應(yīng)的視頻路徑
-
配置輸出流
- 點(diǎn)擊開始錄制
此時(shí)可以查看http://localhost/stat看看服務(wù)器是否接收到錄制的節(jié)目。
有支持rtmp協(xié)議的播放器就可以試試了臂拓,這里可以使用vlc播放器厚脉,輸入rtmp://localhost/live/test,查看直播節(jié)目。