由于业务需要接入海康视频监控,目前有几种办法:
页面展示(如果能直接访问设备ip,不然需要设置,未尝试):
搜索“海康”,“服务支持”-》“sdk开发”,根据环境和位数找到需要的sdk版本。
若要二次开发,
推荐:https://blog.csdn.net/shijieming/article/details/81017921
https://blog.csdn.net/weixin_37460672/article/details/102482040
接入之前确认下设备是否支持RTSP取流。最新海康摄像机、NVR、流媒体服务器、回放取流RTSP地址规则说明
tar jxf ffmpeg-2.5.3.tar.bz2
./configure --enable-shared --enable-libx264 --enable-gpl --enable-x86asm --disable-x86asm --prefix=/usr/local/ffmpeg
ldd ffmpeg
如:'libavdevice.so.58'--> not found
[root@localhost home]# find /usr -name 'libavdevice.so.58'
/usr/local/lib/libavdevice.so.58
/usr/local/install/ffmpeg-4.2.2/libavdevice/libavdevice.so.58
可直接临时添加依赖;若要保存添加依赖,则需要保存到/etc/profile中,source /etc/profile 使其生效.
[root@localhost home]# export LD_LIBRARY_PATH=/usr/local/lib/
然后再尝试执行
[root@localhost home]# /usr/local/ffmpeg/ffmpeg
若无报错,将海康预览地址推送到nginx监听端口(在配置nginx之后执行),出现如下情况无报错和警告为成功
[root@192 ffmpeg-4.2.2]# ffmpeg -i "rtsp://admin:123456@监控IP:554/Streaming/Channels/101?transportmode=unicast" -f flv -r 15 -s 720x480 -an "rtmp://推送IP:1935/oflaDemo/hk"
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-28)
configuration: --enable-shared --enable-libx264 --enable-gpl --enable-x86asm --disable-x86asm
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
[rtsp @ 0x24fe4c0] max delay reached. need to consume packet
[rtsp @ 0x24fe4c0] RTP: missed 30 packets
[h264 @ 0x2501a80] left block unavailable for requested intra4x4 mode -1
[h264 @ 0x2501a80] error while decoding MB 0 7, bytestream 123507
[h264 @ 0x2501a80] concealing 3089 DC, 3089 AC, 3089 MV errors in I frame
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://admin:[email protected]:554/Streaming/Channels/101?transportmode=unicast':
Metadata:
title : HIK Media Server V3.4.103
comment : HIK Media Server Session Description : standard
Duration: N/A, start: 0.320000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1280x720, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
nginx rtmp配置
#rtmp的配置(接收rtmp流)
rtmp {
server {
listen 1935;
#RTMP 直播流配置
application live {
live on;
}
#HLS 直播流配置
application hls {
live on;
hls on; #开启hls
hls_path /home/nginx-rtmp-temp/hls;
hls_fragment 5s; #一个ts 文件的时长 5s
}
}
}
若要通过http访问,需要在http模块添加
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/nginx-rtmp-temp;
add_header Cache-Control no-cache;
#解决video.js使用以后m3u8无法访问的跨域问题
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
}
配置好后,先重新加载nginx配置文件,可通过如下操作将rtsp流转换为rtmp流
ffmpeg -i "rtsp://username:password@ip:port/Streaming/Channels/101?transportmode=unicast" -vcodec copy -acodec copy -f flv "rtmp://nginxIP:1935/hls/test"
然后可用VLC软件或其他软件播放http://nginxIP:httpPort/hls/test.m3u8进行实时播放;test可根据推送的test修改进行修改;