本文链接:https://www.jianshu.com/p/a287e4e9fec3
需求
摄像头广播一个RTSP直播,中转站拉取视频流后,再广播一个公网的RTSP流,客户端拉取RTSP流播放。
实现
实际上,这就是做一个转发服务器,举个例子,海康威视自建服务器,这个服务器拉取监控摄像头的数据,然后转发给用户观看。
使用EasyDarwin流媒体服务器。
下载release版本
https://github.com/EasyDarwin/EasyDarwin/releases
解压后的目录结构是
/opt/EasyDarwin/EasyDarwin
/opt/EasyDarwin/nginx
运行EasyDarwin
cd /opt/EasyDarwin/EasyDarwin
sudo ./start.sh
运行nginx
cd /opt/EasyDarwin/nginx
sudo ./sbin/nginx
我的服务器IP地址是139.199.66.124
检查EasyDarwin是否部署成功
http://139.199.66.124:10008/api/v1/getserverinfo
web后台地址(登录不了)
http://139.199.66.124:10080/
用EasyPusher推流到服务器,推流地址是
rtsp://139.199.66.124:10554/1.sdp
获取当前正在进行RTSP直播的列表
http://139.199.66.124:10008/api/v1/getrtsplivesessions
用vlc播放地址
rtsp://139.199.66.124:10554/1.sdp
但是这样只是实现了push-then-pull,我们要的是pull-then-pull。
ffmpeg推送摄像机视频到EasyDarwin
1、下载ffmpeg
2、例如,我们的摄像机地址是 rtsp://admin:[email protected]/,ffmpeg命令如下:
ffmpeg.exe -i rtsp://admin:[email protected]/ -vcodec copy -acodec copy -rtsp_transport tcp -f rtsp rtsp://127.0.0.1/test.sdp
也可以进行音视频转码后推送:
ffmpeg.exe -i rtsp://admin:[email protected]/ -vcodec libx264 -acodec libvo_aacenc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1/test.sdp
最后,用vlc播放。
附上一些报错
运行nginx报错
nginx: [alert] could not open error log file: open() "/opt/EasyDarwin/nginx/logs/error.log" failed (2: No such file or directory)
解:把nginx目录复制到/opt/EasyDarwin/目录,再运行。
web管理页不能登录
rong@rong-ubuntu-07:~/software/EasyDarwin-Linux-x86_64-v7.3.17.1114/EasyDarwin$ WARNING: Another process is already using the following RTSP port: 10554
WARNING: Another process is already using the following RTSP port: 10008
WARNING: No module folder exists.
未解:
查看端口占用
netstat -a | grep 10080
netstat -a | grep 10554
运行./stop.sh
停止EasyDarwin,把EasyDarwin目录复制到/opt/EasyDarwin/目录,再运行start.sh
sudo cp -r EasyDarwin /opt/EasyDarwin/
ffmpeg转发报错
ffmpeg -i rtsp://192.168.3.9:8554/recorderLive -vcodec copy -acodec copy -f rtsp rtsp://139.199.66.124:10554/1.sdp
ffmpeg version N-89467-g0e52602 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 20160609
configuration:
libavutil 56. 5.100 / 56. 5.100
libavcodec 58. 6.103 / 58. 6.103
libavformat 58. 3.100 / 58. 3.100
libavdevice 58. 0.100 / 58. 0.100
libavfilter 7. 7.100 / 7. 7.100
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
[rtsp @ 0x38983c0] max delay reached. need to consume packet
[rtsp @ 0x38983c0] RTP: missed 1 packets
[h264 @ 0x389b960] concealing 1094 DC, 1094 AC, 1094 MV errors in I frame
Input #0, rtsp, from 'rtsp://192.168.3.9:8554/recorderLive':
Metadata:
title : Live Recorder H.264 Video And AMR-NB Audio, streamed by the LIVE555 Media Server
comment : recorderLive
Duration: N/A, start: 2.353211, bitrate: N/A
Stream #0:0: Video: h264 (High), yuv420p(progressive), 768x432, 15 fps, 14.92 tbr, 90k tbn, 30 tbc
[rtsp @ 0x38d54e0] CSeq 4 expected, 3 received.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Last message repeated 1 times
解:
ffmpeg -i rtsp://192.168.3.9:8554/recorderLive -vcodec copy -acodec copy -rtsp_transport tcp -f rtsp rtsp://139.199.66.124:10554/1.sdp
播放没有声音
解:
摄像头设置直播音频。
参考
用Darwin开发RTSP级联服务器(拉模式转发)(附源码)
在EasyDarwin进行实时视频转发的两种模式
EasyDarwin云平台部署实践
http://www.easydarwin.org/
ffmpeg推送,EasyDarwin转发,vlc播放 实现整个RTSP直播
https://github.com/EasyDarwin/EasyDarwin/tree/master/EasyDarwin