实时视频解决方案 RTSP转RTMP,并转发FLV格式流

最近公司有个项目,要可以看各个设备的实时视频,本来在两天内找了一些参考材料写了一下,里面的链接都是对我开发很有启发的帖子
 
方案来源参考
https://juejin.cn/post/6844903877217632264#comment
 

方案一: html5 + websocket_rtsp_proxy 实现视频流直播

  1. 服务器安装streamedian服务器
  2. 客户端通过video标签播放
 
缺点:收费的,免费版有很多限制
 
暂未尝试
 

方案2 VLC插件

放弃,chrome不支持
 

方案3:ffmpeg + nginx + videojs,rtsp转rtmp播放

https://blog.csdn.net/LLittleF/article/details/81111713
https://blog.csdn.net/qq_22633333/article/details/96288603#comments
rtmp的播放严重依赖flash,而由于flash本身的安全,现代浏览器大多禁用flash
所以需要结合nginx 作为流媒体服务器,在接收rtmp流的同时 转发 flv 格式流出来
 

方案4 ffmpeg + video,rtsp转hls播放

 
https://blog.csdn.net/qq_22633333/article/details/96288603#comments
 
 

以下主要介绍一下我尝试方案3和方案4的过程

 

方案 3 过程

nginx安装 nginx-http-flv-module 模块
https://github.com/winshining/nginx-http-flv-module
 
nginx配置
可以通过nginx服务同时分发rtmp流和http-flv流。
rtmp {
        server {
                listen 1935;
                application live {
                        live on;
                }
                application history {
                        live on;
                }
                application hls {
                        live on;
                        hls on;
                        hls_path temp/hls;
                        hls_fragment 8s;
                }
        }
}

http {
    ......
    server {
        listen       8080;
        server_name	 localhost;
		
		location /live {
			flv_live on;
                    chunked_transfer_encoding  on; #open 'Transfer-Encoding: chunked' response
			add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
			add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
			add_header Access-Control-Allow-Headers X-Requested-With;
			add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
			add_header 'Cache-Control' 'no-cache';
            }
        }
	......
 }

 

安装ffmpeg
yum安装
https://www.myfreax.com/how-to-install-ffmpeg-on-centos-7/
下载安装
https://blog.csdn.net/u013314786/article/details/89682800
 
在window平台安装nginx模块

这个比较复杂,我还没去尝试,因为已经确定服务会部署在 centos 7 上

 

window安装ffmpeg

https://zhuanlan.zhihu.com/p/118362010

Path添加环境变量
bin目录下执行 ffmpeg –version 验证安装成功
 
 
ffmpeg推流 将rtsp转为rtmp
 
1
我试了没有成功
https://zhuanlan.zhihu.com/p/62021755
ffmpeg -i "rtsp://admin:a1234567@192.168.33.3:554" -vcodec copy -acodec copy -f flv "rtmp://127.0.0.1:1935/live/"
 
2
我试了没有成功
https://www.cnblogs.com/pongyc/p/14276712.html
ffmpeg -rtsp_transport tcp -i rtsp://admin:a1234567@192.168.33.3:554 -f flv -r 25 -s 1920*1080 -an rtmp://localhost:1935/live/
 
3
https://my.oschina.net/syscde/blog/3186481
执行下面推流成功!  让他视频转rtmp
 
ffmpeg -rtsp_transport tcp -i rtsp://admin:a1234567@192.168.33.3:554 -vcodec h264 -f flv -an rtmp://localhost:1935/live/room
 
rtmp://localhost:1935/live/room
 
使用VLC测试可以正常播放
 
http部分配置
和上面的nginx.conf一样,这个部分作用主要是转发flv
location /live { flv_live on; chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; add_header 'Cache-Control' 'no-cache'; }
 
访问可以下载无后缀类型文件
 
使用 flv.js 实现网页播放
https://www.jianshu.com/p/547dca89dd43
flv.js 构建出错
直接下载js
https://www.bootcdn.cn/flv.js/
 
问题:
使用 flv.js 过程产生的常见问题
https://blog.csdn.net/epubcn/article/details/103071953
 
使用flv
https://www.cnblogs.com/zhifa/p/13252838.html
 
问题:
chrome自动播放失败解决
https://www.mzwu.com/article.asp?id=4411
https://blog.csdn.net/red_heel/article/details/80508655
 
flv.js 不支持rtmp视频流
https://github.com/Bilibili/flv.js/issues/207
 
videojs播放rtmp流
提示 No compatible source was found for this video
解决方案:
1.将文件放到服务器上,就是别用本地文件的方式打开
 
 

方案 4 过程

该方案只要ffmpeg ,不需要nginx代理 http-flv ,但是播放端不好处理
 
ffmpeg 推流
ffmpeg -i "rtsp://admin:a1234567@192.168.33.3:554" -c copy -f hls -hls_time 2.0 -hls_list_size 0 -hls_wrap 15 "C:/Users/HLF/Desktop/videojs/hls/test.m3u8"
 
VLC可以播放,但是播放完片段会暂停
问题:播放完片段后会卡住,不知道要怎么使它连续播放
 
 视频大小
25帧 360p  (480x360)
1分钟视频大小 接近 3M
 
 
 

posted on 2021-02-25 18:16  蒟蒻鸡  阅读(11218)  评论(2编辑  收藏  举报