环境:海康威视录像机DS-7804NB-K1/4P,Ubuntu16.04
录像机内网地址192.168.100.99,一个摄像头接在4号口(32口以下通道号从33开始),摄像头内网地址 192.168.1.64,服务器内网地址192.168.100.75,测试PC192.168.100.83
从摄像头直接取RTSP流 rtsp://admin:123456@192.168.1.64/Streaming/Channels/1
从录像机取摄像头RTSP流 rtsp://admin:123456@192.168.100.99:554/h264/ch36/main/av_stream
VLC:
sudo apt-get install vlc,
媒体->流->网络->输入摄像头RTSP流->串流->地址rtsp://admin:123456@192.168.100.99:554/h264/ch36/main/av_stream->激活转码、Video-H.264+MP3(MP4)->流->端口5580,路径/hiktest/h264/ch36/main
则流网络地址为rtsp://192.168.100.75:5580/hiktest/h264/ch36/main
EasyDarwin:https://github.com/EasyDarwin/EasyDarwin/releases
下载EasyDanwin,直接解压,sudo bash start.sh
浏览器访问localhost:10008配置推流
输入rtsp://admin:123456@192.168.100.99:554/h264/ch36/main/av_stream
输出/hiktest/h264/ch36/main
则流网络地址为rtsp://192.168.100.75/hiktest/h264/ch36/main
以下步骤以EasyDanwin串流地址为例
安装nginx和rtmp模块(需更新Ubuntu源,nginx需1.14以上才能直接apt安装rtmp的mod):
sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
sudo apt-get install libnginx-mod-rtmp
sudo mkdir /HLS
sudo mkdir /HLS/hls
sudo chmod -R 777 /HLS
sudo chmod -R 777 /HLS/hls
cd /etc/nginx
sudo vi /etc/nginx/sites-enabled/default
在http的server内部加入
location /hls {
#add_header 'Access-Control-Allow-Origin' '*' always;
#add_header 'Access-Control-Expose-Headers' 'Content-Length';
add_header Cache-Control no-cache;
#if ($request_method = 'OPTIONS') {
# add_header 'Access-Control-Allow-Origin' '*';
# add_header 'Access-Control-Max-Age' 1728000;
# add_header 'Content-Type' 'text/plain charset=UTF-8';
# add_header 'Content-Length' 0;
# return 204;
#}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /HLS;
expires -1;
}
sudo nginx -s reload
ffmpeg:http://www.ffmpeg.org/download.html
直接解压,运行
./ffmpeg -rtsp_transport tcp -r 25 -i rtsp://192.168.100.75/hiktest/h264/ch36/main -fflags flush_packets -max_delay 1 -segment_time 5 -an -flags -global_header -hls_time 1 -hls_list_size 3 -hls_wrap 4 -vcodec copy -y /HLS/hls/ch36.m3u8
P.S.这里先串流是因为我直接将原RTSP流做输入时会报错,有待再查证原因;后来出现过Invalid UE golomb code-1.0、pkt->duration = 0, maybe the hls segment duration will not precise、Cannot use rename on non file protocol, this may lead to races and temporary partial files等问题,不太记得具体怎么解决的,注意apt-get install ffmpeg的版本过旧,hls_wrap要比hls_list_size大,最好用-r指定fps
HTML中嵌入
更新:
nginx在nginx.conf配置rtmp模块:
rtmp{
server{
listen 1935;
chunk_size 1024;
application live{
live on;
}
} }
rtsp转rtmp:
ffmpeg -re -rtsp_transport tcp -i rtsp://admin:123456@192.168.0.99:554/h264/ch36/sub/av_stream -f flv -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://localhost:1935/live/stream
参考链接:
https://www.dreamvps.com/tutorials/hls-and-nginx-on-ubuntu/
https://www.cnblogs.com/Jim-william/p/7991928.html
http://mufool.com/2016/08/01/hls-ios-profile/