1、安裝homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
卸載的話运授,輸入
ruby-e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
2、安裝nginx
首先绕辖,得將文件下載到本地
brew tap homebrew/nginx
如果報(bào)錯(cuò)Error: homebrew/nginx was deprecated. This tap is now empty as all its formulae were migrated.,執(zhí)行如下
brew tap denji/nginx
第二步,執(zhí)行安裝
brew install nginx-full--with-rtmp-module
如果出現(xiàn): early EOF若锁,?index-pack failed凌净,
說明源存在問題悲龟,執(zhí)行以下4步
cd "$(brew --repo)"?
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
brew update
會(huì)出現(xiàn)Already up-to-date.,此時(shí)再次執(zhí)行brew install nginx-full--with-rtmp-module
如果報(bào)錯(cuò)Error: No available formula with the name "nginx-full--with-rtmp-module"冰寻, 執(zhí)行?brew install denji/nginx/nginx-full --with-rtmp-module
最后安裝成功
3须教、到這一步, nginx和rtmp就安裝好了,啟動(dòng)服務(wù)
nginx
在瀏覽器輸入http://localhost:8080斩芭,如果出現(xiàn)下圖代表安裝成功
4轻腺、配置rtmp
打開Finder,command+shift+G前往文件夾/usr/local/etc/nginx/nginx.conf划乖,用記事本打開
在http節(jié)點(diǎn)后面加上rtmp配置:
rtmp {? ?
? ? server {? ? ? ?
? ? ? ? listen 2020;? ? ? ?
? ? ? ? application myrtmp {? ? ? ? ? ?
? ? ? ? ? ? live on;? ? ? ? ? ?
? ? ? ? ? ? record off;? ? ? ?
? ? ? ? }? ?
? ? }
}
說明:
rtmp:協(xié)議名稱
server:內(nèi)部中是服務(wù)器相關(guān)配置
listen: 監(jiān)聽的端口號(hào)2020
application: 訪問的應(yīng)用路徑是myrtmp
live on: 開啟實(shí)時(shí)
record off: 不記錄數(shù)據(jù)
添加后保存文件贬养,之后得重啟niginx
nginx-s reload
如果報(bào)這個(gè)錯(cuò)誤:
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
可以執(zhí)行
nginx
到這一步,rtmp服務(wù)就啟動(dòng)成功了
5迁筛、安裝ffmpeg
brew install ffmpeg
安裝過程較慢煤蚌,可以下載一個(gè)VLC播放器測試?yán)鱾溆?/p>
6、通過ffmpeg推流到本地服務(wù)器
ffmpeg-re-i ?“視頻文件的絕對路徑” -vcodec libx264-acodec aac-f flv rtmp://localhost:2020/m yrtmp/room1
如果出現(xiàn)RTMP_Connect0, failed to connect socket. 61 (Connection refused)
rtmp://localhost:2016/rtmplive/room: Unknown error occurred
表示你的nginx服務(wù)未啟動(dòng)细卧,執(zhí)行nginx-s reload或者nginx進(jìn)行啟動(dòng)
在推流的同時(shí)可以打開VLC進(jìn)行驗(yàn)證尉桩,驗(yàn)證方法File->Open Network->輸入 rtmp://localhost:2020/m yrtmp/room1
就會(huì)同步打開視頻進(jìn)行播放。注意:一定要在推流過程中play贪庙,不然會(huì)沒反應(yīng)
服務(wù)器搭建成功啦V├纭!