Nginx
- 安装nginx
brew install nginx
- 运行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 nginximage1.png
- 解决方案:
- 查看报错信息:
$ brew doctor报错内容:
image2.png- 执行命令:
$ brew link pcre错误二:
Error: Could not symlink >>share/man/man3/pcre.3 /usr/local/share/man/man3 is not writable.
- 解决方案
- 执行命令:
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协议拉流路径:
/usr/local/etc/nginx/nginx.conflocation /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协议拉流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到服务器
$ 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到服务器
$ 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,不然在浏览器中无法播放

