前提:
為了不影響服務(wù)器的正常使用拇泛,我在本地搭建了一個(gè)nginx+rtmp服務(wù)器疤估,用來(lái)直播推流測(cè)試。
打開(kāi)咱們的終端照激,開(kāi)始輸入命令:
個(gè)人建議在開(kāi)始之前发魄,不管有沒(méi)有安裝過(guò),先對(duì)其進(jìn)行卸載操作:
執(zhí)行命令:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
1俩垃、安裝Homebrew
執(zhí)行命令:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2励幼、安裝nginx
先把nginx項(xiàng)目放到本地:
執(zhí)行命令:brew tap homebrew/nginx
進(jìn)行安裝:
執(zhí)行命令:brew install nginx-full --with-rtmp-module
3、運(yùn)行nginx
執(zhí)行命令:nginx
然后在瀏覽器中輸入:http://localhost:8080? 點(diǎn)擊回車(chē)口柳,進(jìn)行測(cè)試苹粟,如果出現(xiàn)下面頁(yè)面,說(shuō)明nginx已經(jīng)安裝成功:
4跃闹、配置nginx和rtmp
4.1嵌削、查看nginx安裝位置
執(zhí)行命令:brew info nginx-full
在終端里面會(huì)出現(xiàn)下面的信息:
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
- Tips -
Run port 80:
$ sudo chown root:wheel /usr/local/Cellar/nginx-full/1.10.2/bin/nginx
$ sudo chmod u+s /usr/local/Cellar/nginx-full/1.10.2/bin/nginx
Reload config:
$ nginx -s reload
Reopen Logfile:
$ nginx -s reopen
Stop process:
$ nginx -s stop
Waiting on exit process
$ nginx -s quit
To have launchd start homebrew/nginx/nginx-full now and restart at login:
brew services start homebrew/nginx/nginx-full
Or, if you don't want/need a background service you can just run:
nginx
上面信息粗體+下劃線(xiàn)部分,就是我們本地nginx.conf文件地址:“/usr/local/etc/nginx/nginx.conf”望艺;
“/usr/local/Cellar/nginx-full/1.10.2/bin/nginx”為nginx完整路徑苛秕;
4.2、執(zhí)行以下命令打開(kāi)nginx.conf配置文件來(lái)配置:
執(zhí)行命令:vi /usr/local/etc/nginx/nginx.conf
終端界面最下面會(huì)有下面的內(nèi)容(重要):
# 在http節(jié)點(diǎn)后面加上rtmp配置:
rtmp {
server {
listen 1935;
application rtmplive {
live on;
record off;
}}}
4.3找默、重啟nginx
執(zhí)行命令:/usr/local/Cellar/nginx-full/1.10.0/bin/nginx -s reload
5艇劫、安裝ffmpeg
執(zhí)行命令:brew install ffmpeg
安裝這個(gè)需要一定的時(shí)間,在這個(gè)時(shí)候你可以下載一個(gè)支持RTMP播放的播放器惩激,推薦使用VLC播放器店煞,等終端安裝完畢后,可以進(jìn)行下面的一步风钻;
6顷蟀、ffmpeg推流
執(zhí)行命令:ffmpeg -re -i /Users/jingmei/Desktop/_2jmmxID.mp4-vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/rtmplive/room
注意:上面的“/Users/jingmei/Desktop/_2jmmxID.mp4”是我本地的視頻;
“rtmp://localhost:1935/rtmplive/room”是要改變一下的魄咕,根據(jù)4.2下面的內(nèi)容進(jìn)行更換衩椒,如圖顯示:
如果終端提示服務(wù)器問(wèn)題蚌父,請(qǐng)?jiān)敿?xì)檢查第六步哮兰,當(dāng)終端中出現(xiàn)下面信息,說(shuō)明已經(jīng)推流成功:
到此苟弛,你所想推流的視頻喝滞,已經(jīng)在推流了,你把“rtmp://localhost:1935/rtmplive/room”放在VLC播放器中膏秫,即可以看到你所推送的視頻右遭。