1、安裝命令
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 先clone nginx項目到本地 brew tap homebrew/nginx 執行安裝: brew install nginx-full --with-rtmp-module 此時, nginx和rtmp模塊就安裝好了 輸入命令: nginx 在瀏覽器里打開http://localhost:8080
2、安裝過程中可能出現錯誤
我在安裝過程中需要對brew進行升級
brew update -v
3、安裝完之后的常用指令
查詢安裝路徑:
brew info nginx-full
nginx安裝所在位置 /usr/local/Cellar/nginx-full/1.10.1/bin/nginx nginx配置文件所在位置 /usr/local/etc/nginx/nginx.conf nginx服務器根目錄所在位置 /usr/local/var/www
4、配置RTMP服務
/usr/local/etc/nginx/nginx.conf 中RTMP和Http節點一致
# 在http節點后面加上rtmp配置: rtmp { server { listen 1935; application myapp { live on; #record keyframes; #record_path /tmp; #record_max_size 128K; #record_interval 30s; #record_suffix .this.is.flv; #on_publish http://localhost:8080/publish; #on_play http://localhost:8080/play; #on_record_done http://localhost:8080/record_done; } application hls { live on; hls on; hls_path /tmp/app; hls_fragment 5s; } } }
5、查詢rtmp服務是否正常
修改完配置文件之后執行 nginx -s reload
執行 sudo lsof -i -P | grep -i "listen" 查詢1935端口是否開啟
6、直播測試
安裝ffmpeg
brew install ffmpeg
安裝vlc播放器
准備mp4文件推流測試,用vlc播放
推流:
ffmpeg -re -i /Users/lunli/rtmp/keep.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/myapp/room
播放:
rtmp://localhost:1935/myapp/room
7、如果遇到錯誤
卸載nginx,重新安裝
8、結果
9、視頻文件參考了https://github.com/sunjinshuai/Keep/blob/master/KeepGuidePage/keep.mp4