一、rtmp局限性
由于各家浏览器到今年年底不在支持flash,所以在视频监控将rtsp流转换成让rtmp的方式需要改进。
二、环境准备
1、下载nginx包
下载地址:/download/nginx-1.14.
2、下载nginx-http-flv-module 模块包
下载地址:/winshining/nginx-http-flv-module
3、创建目录 /opt/tools
安装虚拟机,并在opt文件夹下新建一个文件夹tools ,将下载的nginx 和nginx-rtmp-module 拷贝到opt 文件夹下
4、创建nginx 文件夹
mkdir /usr/local/nginx
三、环境搭建
1、解压nginx-http-flv-module-master,并放到/usr/local/nginx下面
2、将nginx-http-flv-module模板添加到nginx中,生成make文件并安装nginx
cd /opt/tools
tar -zxvf nginx-1.8.
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx/nginx-http-flv-module
make && make install
3、配置文件修改,github上有示例参考
#user nobody;
worker_processes 10;
#error_log logs/;
#error_log logs/ notice;
#error_log logs/ info;
#pid logs/;
events {
worker_connections 10240;
}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp{
out_queue 4096;
out_cork 8;
max_streams 128;
timeout 15s;
drop_idle_publisher 15s;
log_interval 5s;
log_size 1m;
server{
listen 1935;
server_name 127.0.0.1;
application myapp{
live on;
gop_cache on;
}
application hls{
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
}
application dash{
live on;
dash on;
dash_path /usr/local/nginx/html/dash;
}
}
}
http{
include ;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8002;
server_name 127.0.0.1;
location /live{
flv_live on;
chunked_transfer_encoding on;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
location / {
root html;
index ;
}
error_page 500 502 503 504 /;
location = / {
root html;
}
location /hls{
types {
application/ m3u8;
video/mp2t ts;
}
root /usr/local/nginx/html/hls;
add_header 'Cache-Control' 'no-cache';
}
location /dash {
root /usr/local/nginx/html/dash;
add_header 'Cache-Control' 'no-cache';
}
location /stat {
#configuration of push & pull status
rtmp_stat all;
rtmp_stat_stylesheet ;
}
location / {
root /usr/local/nginx/nginx-http-flv-module;
}
location /control {
rtmp_control all;
}
}
}
四、http-flv流测试
1、安装ffmpeg,网上有很多方法
2、大华摄像机ffmpeg命令:
ffmpeg -i "rtsp://<username>:<password>@<ip地址>:554/cam/realmonitor?channel=1&subtype=0" -rtsp_transport tcp -vcodec copy -acodec copy -f flv "rtmp://127.0.0.1:1935/myapp/test"
3、http-flv流格式
http://<ip>:8002/live?port=1935&app=myapp&stream=test
五、问题汇总
1、转流时报错情况:
[tcp @ 0x1826bc0]Connection to tcp://127.0.0.1:1935 failed: Connection refused
解决方法:除了更改文件,还要同步修改文件
2、重启nginx (./nginx -s reload)
报错:nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/"
解决方法:执行命令 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/