日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

海康NVR设备RTSP协议转RTMP协议

發布時間:2024/3/24 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 海康NVR设备RTSP协议转RTMP协议 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Title:海康NVR設備RTSP協議轉RTMP協議
Date: 2017-10-17
Author: kagula

環境:
[1]??礜VR設備? 型號為DS-7808N-E2/8P
[2]CentOS7?
[3]Chrome 61.0.3163.79
[4]Safari 5.1.7


內容概要
? ?海康NVR設備上的RTSP協議轉RTMP協議,Chrome等瀏覽器上就能直接看??低曇曨l。
本文分為三個部份:Nginx配置和安裝,ffmpeg配置和安裝,運行和測試。


內容
第一部份:Nginx的安裝、配置和使用
[1-1]nginx-rtmp-module模塊

為了增加對rtmp的支持,下載nginx-rtmp-module解壓到/root/download/nginx-rtmp-module
配置和編譯nginx的時候要用到。
[1-2]安裝nginx的依賴
yum? -y install openssl openssl-devel
yum -y install pcre-devel
[1-3]下載nginx-1.10.3.tar.gz源碼包并解壓
進入到nginx解壓路徑后,使用下面的命令配置nginx及其module
?./configure --prefix=/usr/local/nginx? --add-module=/root/download/nginx-rtmp-module? --with-http_ssl_module?
[1-4]編譯并安裝
make
make install
[1-5]配置nginx對rtmp的支持
vim /usr/local/nginx/conf/nginx.conf
加入下面的配置
rtmp {
? server {
? ? listen 1935;
? ? application hls {
? ? ? live on;
? ? ? hls on;
? ? ? hls_path /tmp/hls;
? ? ? hls_fragment 1s;
? ? ? #hls_playlist_length 3s;
? ? }
? }
}

live on; 開啟實時
hls on; 開啟hls
hls_path;? ? ? ? ? ?
? ? ? ? ? http://xxx/hls這個地址可以用來推流和拉流,其中xxx是你的ip地址或域名。
? ? ? ? ? 它會被映射到/tmp/hls本地路徑下。
? ? ? ? ? ts文件存放路徑,使用絕對路徑
hls_fragment 5s; 每個TS文件包含5秒的視頻內容


[1-6]啟動nginx
/usr/local/nginx/sbin/nginx
啟動時可能會遇到端口占用的問題,如果之前nginx已經啟動了,先把進程停止
nginx -s quit
如果nginx起來后,修改了配置文件
使用/usr/local/nginx/sbin/nginx -s reload重啟nginx服務




[1-7]檢查服務是否已經啟動
netstat -ntlp
看到1935和80端口已經在偵聽狀態


第二部份:FFMPEG的安裝、配置和使用
[2-1]下載

wget http://ffmpeg.org/releases/ffmpeg-3.4.tar.bz2
然後再解壓縮。


[2-2]安裝依賴
yum install nasm


[2-3]安裝&配置
配置
./configure --enable-shared --prefix=/usr/local/ffmpeg
make
可能需要幾分鐘
make install
現在ffmpeg已經被安裝到了/usr/local/ffmpeg路徑下。


添加動態庫文件搜索路徑
vim /etc/ld.so.conf
把/usr/local/ffmpeg/lib路徑添加到ld.so.conf中的最後一行。
使用下面的命令讓修改生效
ldconfig


[2-4]使用
使用前先驗證rtsp源是否可以播放
可以使用EasyPlayer播放器驗證視頻源
rtsp://admin:nuoke123456@192.168.2.226:554/Streaming/Channels/101
EasyPlayer可以從下面網址下載
https://github.com/EasyDarwin/EasyPlayer/releases/tag/v2.0.17.0709


確定視頻源沒問題后使用下面的命令轉碼
./ffmpeg -f rtsp -rtsp_transport tcp -i rtsp://admin:nuoke123456@192.168.2.226:554/Streaming/Channels/101 -codec copy -f flv -an rtmp://192.168.109.129:1935/hls/test
-f rtsp 輸入流是rtsp協議
-rtsp_transport tcp 輸入流是tcp協議
-i rtsp://admin:nuoke123456@192.168.2.226:554/Streaming/Channels/101 指定輸入流
-f flv 輸出流為flv格式
-an rtmp://192.168.109.129:1935/hls/test 指定推送地址
如果推送成功的話/tmp/hls路徑下會生成多個tls文件和test.m3u8文件。

第三部份:測試和運行
[1]可以用PotPlayer播放器測試RTMP數據源是否正確
[2]用Chrome、Safari瀏覽器測試RTMP數據源是否能正確播放

rtmp.html的清單

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="http://vjs.zencdn.net/5.19/video-js.min.css" rel="stylesheet"> <script src="http://vjs.zencdn.net/5.19/video.min.js"></script> </head> <body> <videoid="my-player"class="video-js"controlspreload="auto"data-setup='{}'><source src='rtmp://192.168.109.129:1935/hls/test' type='rtmp/flv'/> </p> </video> <script type="text/javascript">var options = {};var player = videojs('my-player', options, function onPlayerReady() {videojs.log('Your player is ready!');// In this context, `this` is the player that was created by Video.js.this.play();// How about an event listener?this.on('ended', function() {videojs.log('Awww...over so soon?!');});});</script> </body> </html

必須要放在Web服務器上才能正確運行,本地用chrome打開這個html文件是沒用的。
我把它放在了/usr/local/nginx/html路徑下,這是我Nginx的document root路徑.
使用chrome訪問 http://192.168.109.129/rtmp.html可以直接看到視頻。

備注
[1]RTSP數據源可以適配到adobe的FMS、Wowza、800li media server。
[2]??档默撌?#xff0c;提供RTMP視頻流服務!
[3]防火墻打開了1935 tcp端口,rtmp視頻還是不能播放,
可以用下面的命令暫停,
systemctl stop firewalld.service


參數資料
[1]最新??禂z像機、NVR、流媒體服務器、回放取流RTSP地址規則說明
http://blog.csdn.net/xiejiashu/article/details/71786187
[2]EasyDSS流媒體服務器出現no compatible source was found for this media問題的解決
http://blog.csdn.net/xiejiashu/article/details/72371149


擴展閱讀
[1]Mac直播服務器Nginx配置對HLS的支持
http://www.cnblogs.com/jys509/p/5653720.html
[2]Ubuntu下使用Python-opencv獲取??低昍TSP碼流教程
http://blog.csdn.net/hui3909/article/details/53435379

總結

以上是生活随笔為你收集整理的海康NVR设备RTSP协议转RTMP协议的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。