1,下載,編譯 nignix nignx-rtmp-mpdule
編譯nginx時需要nignx-rtmp-mpdule的包加入
git clone https://github.com/arut/nginx-rtmp-module.git
wget http://nginx.org/download/nginx-1.7.5.tar.gz
放置於同一個目錄
tar -xvf nginx-1.7.5.tar.gz
cd nginx-1.7.5/
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make
make install
安裝到 /usr/local
cd /usr/local
cd nginx/
wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
chmod a+x /etc/init.d/nginx
update-rc.d nginx defaults
service nginx start
service nginx stop
默認啟動80端口監聽
修改監聽端口
cd conf/
cp nginx.conf nginx.conf-bak
vi nginx.conf
修改http下的端口為8080
再次啟動
瀏覽器打開localhost:8080
安裝完成
增加nginx-rtmp 狀態查看頁面
解壓nginx-rtmp下的html.tar.gz包
到/usr/local/nginx/html
2.修改nginx配置 加入rmpt配置
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
application live360p {
live on;
record off;
}
}
}
添加stat查看相關的配置項
server {
listen 60010;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root html;
}
location /hls {
#server hls fragments
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias temp/hls;
expires -1;
}
配置完成 重啟nginx
3.使用ffmpeg推流
windows平台 下載http://ffmpeg.org/documentation.html的static包
將解壓后的目錄中bin目錄添加到環境變量
cmd 輸入
ffmpeg -stream_loop -1 -re -i rtsp://winIp/media/video/Dubai.mkv -acodec copy -vcodec libx264 -f flv rtmp://unbuntuIp:1935/live/video1
其中:
rtsp://winIp/media/video/Dubai.mkv為使用vlc播出的流
rtmp://unbuntuIp:1935/live/video1為推向ngix-rtmp服務的流
命令執行后 無報錯及執行成功
使用
播放流 cmd 輸入命令 ffmpeg -i rtmp://unbuntuIp:1935/live/video1
播出成功。
===================
如果是centos7.5
啟動腳本:
[root@~]# cat /lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
然后使用命令:
systemctl enable nginx.service
systemctl start nginx.service
查看啟動情況