下載地址
1、Nginx:https://github.com/nginx/nginx
2、OpenSSL:https://github.com/openssl/openssl
3、rtmp:https://github.com/arut/nginx-rtmp-module
注意:
1、pcre:http://www.pcre.org/
點這個鏈接
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
不要去
https://sourceforge.net/projects/pcre/ 下載最新的
2、zlib:http://www.zlib.net/
安裝PCRE、ZLIB
1、./configure
2、make
3、make install
編譯Nginx
1、編譯OpenSSL
./config --prefix=`pwd`/libs
make
make install
2、編譯Nginx
openssl= 是上面OpenSSL 的目錄
module = 是之前解壓過的rtmp 模塊的目錄
cd 到Nginx 路徑
./auto/configure --add-module=/usr/work/nginx/nginx-rtmp-module-1.2.1 --with-openssl=/usr/work/nginx/openssl-OpenSSL_1_1_1a
make
make install
Nginx生成目錄:/usr/local/nginx
安裝Nginx時報錯
./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
配置Nginx
用:
nginx-rtmp-module-1.2.1/test/nginx.conf
替換
/usr/local/nginx/conf/nginx.conf
拷貝命令:
cp /usr/work/nginx/nginx-rtmp-module-1.2.1/test/nginx.conf /usr/local/nginx/conf/
修改nginx.conf 文件
location /stat.xsl {
root /path/to/nginx-rtmp-module/;
}
這個是rtmp-module 的位置 需要改成自己的
/usr/work/nginx/nginx-rtmp-module-1.2.1
這是我的rtmp-module 的路徑 替換一下
location /stat.xsl {
root /usr/work/nginx/nginx-rtmp-module-1.2.1/;
}
其他幾個同樣的道理 也要改過來 最終
http {
server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/work/nginx/nginx-rtmp-module-1.2.1/;
}
location /control {
rtmp_control all;
}
#location /publish {
# return 201;
#}
#location /play {
# return 202;
#}
#location /record_done {
# return 203;
#}
location /rtmp-publisher {
root /usr/work/nginx/nginx-rtmp-module-1.2.1/test;
}
location / {
root /usr/work/nginx/nginx-rtmp-module-1.2.1/test/www;
}
}
}
啓動停止Nginx
來到 usr/local/nginx/sbin 下 執行下面的命令
1、啓動:
./nginx
或者
/usr/local/nginx/sbin/nginx
2、停止
./nginx -s stop
/usr/local/nginx/sbin/nginx -s stop
判斷當前nginx 是否啓動
ps -ef | grep nginx
問題:
啓動了無法訪問 需要去阿里雲後臺開啓80 8080 端口
安裝telnet
yum install telnet
查看端口是否開放
netstat -aptn
命令行,查看所有開啓的端口號
測試推流
下載ffmpge
把ffmpeg 加入環境變量
我是mac
執行下面的命令
brew install ffmpeg --option
如果出現長時間等待 換源
替換brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替換homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
再執行上面的 安裝命令
下面是 重置爲原來的源
重置brew.git:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git
重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
執行推流
ffmpeg -re -i yaoshen.mp4 -vcodec libx264 -acodec aac -f flv rtmp://你的服務器IP地址/myapp/mystream