Centos7.x 搭建RTSP流處理環境
服務器環境
- 服務器 centos 7 目前版本CentOS Linux release 7.6.1810下載地址
安裝nginx & nginx-rtmp-module
-  下載依賴pcre 目前版本 pcre-8.38下載地址 使用pcre2 nginx會編譯失敗
-  下載依賴zlib 目前版本 zlib-1.2.11下載地址
-  下載openssl 目前版本 openssl-1.0.2s下載地址
-  下載nginx-rtmp-module git clone https://github.com/arut/nginx-rtmp-module.git
-  安裝gcc g++ yum install gcc yum install gcc-c++
-  安裝pcre -  解壓pcre tar -zxvf pcre-8.38.tar.gz
-  進入解壓后的文件夾 cd pcre-8.38
-  編譯前配置 ./configure
-  編譯 make
-  安裝 make install
 
-  
-  安裝zlib -  解壓zlib tar -zxvf zlib-1.2.11.tar.gz
-  進入解壓后的文件夾 cd zlib-1.2.11
-  編譯前配置 ./configure
-  編譯 make
-  安裝 make install
 
-  
-  安裝openssl -  解壓openssl tar -zxvf openssl-1.0.2s.tar.gz
-  進入解壓后的文件夾 cd openssl-1.0.2s
-  編譯前配置 ./configure
-  編譯 make
-  安裝 make install
 
-  
-  安裝nginx -  解壓nginx tar -zxvf nginx-1.17.0.tar.gz
-  進入解壓后的文件夾 cd nginx-1.17.0
-  編譯前配置 # 配置解釋 ./configure --prefix=/usr/local/nginx --with-pcre=/root/pcre-8.38 # pcre路徑 如有不同需要修改 --with-zlib=/root/zlib-1.2.11 # zlib路徑 如有不同需修改 --with-openssl=/root/openssl-1.0.2s # openssl路徑 如有不同需修改 --add-module=/root/nginx-rtmp-module # nginx-rtmp-module路徑 如有不同需要修改 # 運行時去掉換行 ./configure --prefix=/usr/local/nginx --with-pcre=/root/pcre-8.38 --with-zlib=/root/zlib-1.2.11 --with-openssl=/root/openssl-1.0.2s --add-module=/root/nginx-rtmp-module
-  編譯 make
-  安裝 make install
 
-  
-  /etc/init.d目錄下創建 nginx 文件touch /etc/init.d/nginx
-  編輯nginx文件 -  vim 打開 vim /etc/init.d/nginx
-  復制以下內容 #!/bin/bash #Startup script for the nginx Web Server #chkconfig: 2345 85 15 nginx=/usr/local/nginx/sbin/nginx conf=/usr/local/nginx/conf/nginx.conf case $1 in start) echo -n "Starting Nginx" $nginx -c $conf echo " done." ;; stop) echo -n "Stopping Nginx" killall -9 nginx echo " done." ;; test) $nginx -t -c $conf echo "Success." ;; reload) echo -n "Reloading Nginx" ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP echo " done." ;; restart) $nginx -s reload echo "reload done." ;; *) echo "Usage: $0 {start|restart|reload|stop|test|show}" ;; esac
-  保存並退出 
 
-  
-  編輯nginx配置文件 -  打開配置文件 vim /usr/local/nginx/conf/nginx.conf
-  添加以下配置 rtmp { #rtmp 協議 server { listen 9999; #端口號 application live{ live on; record off; } application hls{ #輸出路徑 live on; hls on; hls_path nginx-rtmp-module/hls; hls_cleanup off; } } }
-  保存並退出 
 
-  
-  啟動nginx service nginx start
-  安裝ffmpeg -  yum升級 sudo yum install epel-release -y sudo yum update -y
-  安裝第三方源 sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
-  安裝ffmpeg sudo yum install ffmpeg ffmpeg-devel -y
 
-  
-  rtsp 轉 rtmp 流 # 命令解釋 ffmpeg -i "rtsp://admin:admin@192.168.1.208:46599/cam/realmonitor?channel=1&subtype=0" #攝像頭地址 -f flv -r 15 -an "rtmp://192.168.1.240:9999/hls/demo" #輸出地址 要和ningx一致 demo可以自定義 # 運行時需要去除換行 # 命令行啟動 ffmpeg -i "rtsp://admin:admin@192.168.1.208:46599/cam/realmonitor?channel=1&subtype=0" -f flv -r 15 -an "rtmp://192.168.1.240:9999/hls/demo" >> ./log/ffmpeg.out # 后台啟動 建議寫成shell腳本 nohup ffmpeg -i "rtsp://admin:admin@192.168.1.208:46599/cam/realmonitor?channel=1&subtype=0" -f flv -r 15 -an "rtmp://192.168.1.240:9999/hls/demo" >> ./log/ffmpeg.out 2>&1 &
-  問題 -  無法訪問端口 可能是防火牆開啟中 可以關閉防火牆 # 關閉防火牆命令: systemctl stop firewalld # 開啟防火牆 systemctl start firewalld # 關閉開機自啟動 systemctl disable firewalld.service # 開啟開機啟動 systemctl enable firewalld.service
-  ffmpeg解碼時掉線不會重連 目前尚未解決 
-  花屏,需要下載ffmpeg源碼然后修改並重新編譯 
 在ffmpeg源碼udp.c中:將#define UDP_MAX_PKT_SIZE 65536修改為#define UDP_MAX_PKT_SIZE 655360,或者更大值
 
-  
