Nginx
- 安裝nginx
brew install nginx
- 運(yùn)行nginx
- 啟動:
sudo nginx
- 重啟:
sudo nginx -s reload
- 停止:
sudo nginx -s stop
- 啟動:
- 在瀏覽器中啟動:
http://localhost:8080
如果啟動
nginx
報錯錯誤一:
dyld: Library not loaded: >>/usr/local/opt/pcre/lib/libpcre.1.dylib Referenced from: /usr/local/bin/nginx Reason: image not found [1] 15549 abort sudo nginx
image1.png
- 解決方案:
- 查看報錯信息:
$ brew doctor
報錯內(nèi)容:
image2.png- 執(zhí)行命令:
$ brew link pcre
錯誤二:
Error: Could not symlink >>share/man/man3/pcre.3 /usr/local/share/man/man3 is not writable.
- 解決方案
- 執(zhí)行命令:
sudo chown -R mcbird /usr/local/share/man/man3
Nginx-full
-
安裝
nginx-full
$ brew tap denji/nginx
$ brew install nginx-full --with-rtmp-module
-
配置
nginx
轰坊,支持http
協(xié)議拉流路徑:
/usr/local/etc/nginx/nginx.conf
location /hls { #Serve HLS config types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /usr/local/var/www; add_header Cache-Control no-cache; }
此段代碼是放在
http
括號中 -
配置
nginx
渡贾,支持rtmp
協(xié)議拉流rtmp { server { listen 1935; application rtmplive { live on; max_connections 1024; } application hls{ live on; hls on; hls_path /usr/local/var/www/hls; hls_fragment 1s; } } }
此段代碼是放在與
http
同級位置 重啟
nginx
:$ sudo nginx -s reload
本地推流
- 推流到RTMP到服務(wù)器
$ ffmpeg -re -i 視屏文件.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/rtmplive/demo
- 生成的地址:
rtmp://localhost:1935/rtmplive/demo
(在VLC
中播放)
- 推流至HLS到服務(wù)器
$ ffmpeg -re -i 視屏文件.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/hls/demo
- 生成地址:
http://localhost:8080/hls/demo.m3u8
(在safari
瀏覽器中播放)
疑惑: 推流至hls,地址只能是
rtmp://localhost:1935/hls/demo
, 不能是rtmp://localhost:1935/rtmplive/demo
,不然在瀏覽器中無法播放