今日朝中无事,捣鼓了一下 nginx rtmp,花了一些时间,过程记录以下。html
1] [Getting-started-with-nginx-rtmpnginx
首次参照参考教材惨烈失败,EI CAPITAN 编译 nginx 时报 openssl 错误。git
换用 brew 安装好了github
brew updateapp
brew install nginx-full --with-rtmp-moduletcp
brew info nginx-full 查看安装以后的信息测试
先顺便弄一下命令行的sublimespa
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
nginx的配置文件路径在 /usr/local/etc/nginx命令行
将配置文件修改成 (去除了注释掉的部分)debug
#user nobody; worker_processes 1; error_log logs/error.log debug; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8080; server_name localhost; # rtmp stat location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # 这个路径必定要改 root /usr/local/Cellar/rtmp-nginx-module/1.1.7.9/share/rtmp-nginx-module; } # rtmp control location /control { rtmp_control all; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } rtmp { server { listen 1935; ping 30s; notify_method get; application myapp { live on; } } }
编辑好以后 sudo nginx -s reload 从新加载配置文件
系统自带了几个MOV,地址在 /System/Library/Compositions/
以前安装的ffmpeg没有带ffplay,重装一下。
brew unlink ffmpeg
brew install ffmpeg --with-ffplay
正儿八经的开始测试
访问一把 http://localhost:8080/stat,若是正常打开,表示你已经成功了一大半
cd /System/Library/Compositions/
ffmpeg -re -i Yosemite.mov -c copy -f flv rtmp://localhost/myapp/mystream
ffplay rtmp://localhost/myapp/mystream
开始可能会出现以下的链接错误
Connection to tcp://localhost:1935 failed (Connection refused), trying next address
稍等几秒,不出意外的话,会弹出一个本地的播放器对话框。
哈哈,接下来看如何作个分片什么的