海康NVR设备RTSP协议转RTMP协议
生活随笔
收集整理的這篇文章主要介紹了
海康NVR设备RTSP协议转RTMP协议
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Title:海康NVR設(shè)備RTSP協(xié)議轉(zhuǎn)RTMP協(xié)議
Date: 2017-10-17
Author: kagula
環(huán)境:
[1]海康NVR設(shè)備? 型號(hào)為DS-7808N-E2/8P
[2]CentOS7?
[3]Chrome 61.0.3163.79
[4]Safari 5.1.7
內(nèi)容概要
? ?海康NVR設(shè)備上的RTSP協(xié)議轉(zhuǎn)RTMP協(xié)議,Chrome等瀏覽器上就能直接看海康威視視頻。
本文分為三個(gè)部份:Nginx配置和安裝,ffmpeg配置和安裝,運(yùn)行和測(cè)試。
內(nèi)容
第一部份:Nginx的安裝、配置和使用
[1-1]nginx-rtmp-module模塊
為了增加對(duì)rtmp的支持,下載nginx-rtmp-module解壓到/root/download/nginx-rtmp-module
配置和編譯nginx的時(shí)候要用到。
[1-2]安裝nginx的依賴
yum? -y install openssl openssl-devel
yum -y install pcre-devel
[1-3]下載nginx-1.10.3.tar.gz源碼包并解壓
進(jìn)入到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對(duì)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; 開啟實(shí)時(shí)
hls on; 開啟hls
hls_path;? ? ? ? ? ?
? ? ? ? ? http://xxx/hls這個(gè)地址可以用來推流和拉流,其中xxx是你的ip地址或域名。
? ? ? ? ? 它會(huì)被映射到/tmp/hls本地路徑下。
? ? ? ? ? ts文件存放路徑,使用絕對(duì)路徑
hls_fragment 5s; 每個(gè)TS文件包含5秒的視頻內(nèi)容
[1-6]啟動(dòng)nginx
/usr/local/nginx/sbin/nginx
啟動(dòng)時(shí)可能會(huì)遇到端口占用的問題,如果之前nginx已經(jīng)啟動(dòng)了,先把進(jìn)程停止
nginx -s quit
如果nginx起來后,修改了配置文件
使用/usr/local/nginx/sbin/nginx -s reload重啟nginx服務(wù)
[1-7]檢查服務(wù)是否已經(jīng)啟動(dòng)
netstat -ntlp
看到1935和80端口已經(jīng)在偵聽狀態(tài)
第二部份: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
現(xiàn)在ffmpeg已經(jīng)被安裝到了/usr/local/ffmpeg路徑下。
添加動(dòng)態(tài)庫文件搜索路徑
vim /etc/ld.so.conf
把/usr/local/ffmpeg/lib路徑添加到ld.so.conf中的最後一行。
使用下面的命令讓修改生效
ldconfig
[2-4]使用
使用前先驗(yàn)證rtsp源是否可以播放
可以使用EasyPlayer播放器驗(yàn)證視頻源
rtsp://admin:nuoke123456@192.168.2.226:554/Streaming/Channels/101
EasyPlayer可以從下面網(wǎng)址下載
https://github.com/EasyDarwin/EasyPlayer/releases/tag/v2.0.17.0709
確定視頻源沒問題后使用下面的命令轉(zhuǎn)碼
./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協(xié)議
-rtsp_transport tcp 輸入流是tcp協(xié)議
-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路徑下會(huì)生成多個(gè)tls文件和test.m3u8文件。
第三部份:測(cè)試和運(yùn)行
[1]可以用PotPlayer播放器測(cè)試RTMP數(shù)據(jù)源是否正確
[2]用Chrome、Safari瀏覽器測(cè)試RTMP數(shù)據(jù)源是否能正確播放
必須要放在Web服務(wù)器上才能正確運(yùn)行,本地用chrome打開這個(gè)html文件是沒用的。
我把它放在了/usr/local/nginx/html路徑下,這是我Nginx的document root路徑.
使用chrome訪問 http://192.168.109.129/rtmp.html可以直接看到視頻。
備注
[1]RTSP數(shù)據(jù)源可以適配到adobe的FMS、Wowza、800li media server。
[2]海康的瑩石云,提供RTMP視頻流服務(wù)!
[3]防火墻打開了1935 tcp端口,rtmp視頻還是不能播放,
可以用下面的命令暫停,
systemctl stop firewalld.service
參數(shù)資料
[1]最新海康攝像機(jī)、NVR、流媒體服務(wù)器、回放取流RTSP地址規(guī)則說明
http://blog.csdn.net/xiejiashu/article/details/71786187
[2]EasyDSS流媒體服務(wù)器出現(xiàn)no compatible source was found for this media問題的解決
http://blog.csdn.net/xiejiashu/article/details/72371149
擴(kuò)展閱讀
[1]Mac直播服務(wù)器Nginx配置對(duì)HLS的支持
http://www.cnblogs.com/jys509/p/5653720.html
[2]Ubuntu下使用Python-opencv獲取海康威視RTSP碼流教程
http://blog.csdn.net/hui3909/article/details/53435379
Date: 2017-10-17
Author: kagula
環(huán)境:
[1]海康NVR設(shè)備? 型號(hào)為DS-7808N-E2/8P
[2]CentOS7?
[3]Chrome 61.0.3163.79
[4]Safari 5.1.7
內(nèi)容概要
? ?海康NVR設(shè)備上的RTSP協(xié)議轉(zhuǎn)RTMP協(xié)議,Chrome等瀏覽器上就能直接看海康威視視頻。
本文分為三個(gè)部份:Nginx配置和安裝,ffmpeg配置和安裝,運(yùn)行和測(cè)試。
內(nèi)容
第一部份:Nginx的安裝、配置和使用
[1-1]nginx-rtmp-module模塊
為了增加對(duì)rtmp的支持,下載nginx-rtmp-module解壓到/root/download/nginx-rtmp-module
配置和編譯nginx的時(shí)候要用到。
[1-2]安裝nginx的依賴
yum? -y install openssl openssl-devel
yum -y install pcre-devel
[1-3]下載nginx-1.10.3.tar.gz源碼包并解壓
進(jìn)入到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對(duì)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; 開啟實(shí)時(shí)
hls on; 開啟hls
hls_path;? ? ? ? ? ?
? ? ? ? ? http://xxx/hls這個(gè)地址可以用來推流和拉流,其中xxx是你的ip地址或域名。
? ? ? ? ? 它會(huì)被映射到/tmp/hls本地路徑下。
? ? ? ? ? ts文件存放路徑,使用絕對(duì)路徑
hls_fragment 5s; 每個(gè)TS文件包含5秒的視頻內(nèi)容
[1-6]啟動(dòng)nginx
/usr/local/nginx/sbin/nginx
啟動(dòng)時(shí)可能會(huì)遇到端口占用的問題,如果之前nginx已經(jīng)啟動(dòng)了,先把進(jìn)程停止
nginx -s quit
如果nginx起來后,修改了配置文件
使用/usr/local/nginx/sbin/nginx -s reload重啟nginx服務(wù)
[1-7]檢查服務(wù)是否已經(jīng)啟動(dòng)
netstat -ntlp
看到1935和80端口已經(jīng)在偵聽狀態(tài)
第二部份: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
現(xiàn)在ffmpeg已經(jīng)被安裝到了/usr/local/ffmpeg路徑下。
添加動(dòng)態(tài)庫文件搜索路徑
vim /etc/ld.so.conf
把/usr/local/ffmpeg/lib路徑添加到ld.so.conf中的最後一行。
使用下面的命令讓修改生效
ldconfig
[2-4]使用
使用前先驗(yàn)證rtsp源是否可以播放
可以使用EasyPlayer播放器驗(yàn)證視頻源
rtsp://admin:nuoke123456@192.168.2.226:554/Streaming/Channels/101
EasyPlayer可以從下面網(wǎng)址下載
https://github.com/EasyDarwin/EasyPlayer/releases/tag/v2.0.17.0709
確定視頻源沒問題后使用下面的命令轉(zhuǎn)碼
./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協(xié)議
-rtsp_transport tcp 輸入流是tcp協(xié)議
-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路徑下會(huì)生成多個(gè)tls文件和test.m3u8文件。
第三部份:測(cè)試和運(yùn)行
[1]可以用PotPlayer播放器測(cè)試RTMP數(shù)據(jù)源是否正確
[2]用Chrome、Safari瀏覽器測(cè)試RTMP數(shù)據(jù)源是否能正確播放
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服務(wù)器上才能正確運(yùn)行,本地用chrome打開這個(gè)html文件是沒用的。
我把它放在了/usr/local/nginx/html路徑下,這是我Nginx的document root路徑.
使用chrome訪問 http://192.168.109.129/rtmp.html可以直接看到視頻。
備注
[1]RTSP數(shù)據(jù)源可以適配到adobe的FMS、Wowza、800li media server。
[2]海康的瑩石云,提供RTMP視頻流服務(wù)!
[3]防火墻打開了1935 tcp端口,rtmp視頻還是不能播放,
可以用下面的命令暫停,
systemctl stop firewalld.service
參數(shù)資料
[1]最新海康攝像機(jī)、NVR、流媒體服務(wù)器、回放取流RTSP地址規(guī)則說明
http://blog.csdn.net/xiejiashu/article/details/71786187
[2]EasyDSS流媒體服務(wù)器出現(xiàn)no compatible source was found for this media問題的解決
http://blog.csdn.net/xiejiashu/article/details/72371149
擴(kuò)展閱讀
[1]Mac直播服務(wù)器Nginx配置對(duì)HLS的支持
http://www.cnblogs.com/jys509/p/5653720.html
[2]Ubuntu下使用Python-opencv獲取海康威視RTSP碼流教程
http://blog.csdn.net/hui3909/article/details/53435379
總結(jié)
以上是生活随笔為你收集整理的海康NVR设备RTSP协议转RTMP协议的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用nudge4j从浏览器进入JVM
- 下一篇: 自动交易程序介绍——普通个人和团队如何快