一、问题背景
最近有个业务需求用到node中间层使用ffmpeg对rtsp流转码成MP4推给前端,本地开发基本完成并且能完美运行,但是通过docker部署时发现ffmpeg不能正常使用,根据Log一步步排查,发现可能时端口以及协议问题。
docker容器内环境:
- node v12.0
- Debian GNU/Linux 9
- ffmpeg 3.2.10-1~deb9u1
二、报错问题
通过排查日志,发现在docker中试用ffmpeg请求rtsp流时,UDP端口时无法返回的,报错如下:
[rtsp @ 0x5650696e2580] UDP timeout, retrying with TCP
[rtsp @ 0x5650696e2580] method SETUP failed: 454 Session Not Found
[rtsp @ 0x5650696e2580] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
三、解决方案
-
尝试创建容器时指定暴露一个UDP端口,但依然报错,问题原因未知
-
强制将ffmpeg对rtsp拉流时试用tcp协议,目前有效,加上
-rtsp_transport tcp
参数
ffmpeg -rtsp_transport tcp -i 'rtsp://admin:admin123!@192.168.15.2:554/cam/realmonitor?channel=17&subtype=0' -an -c:v copy -f mp4 -movflags +frag_keyframe+empty_moov+default_base_moof pipe:1
但是性能上是存在问题的,毕竟tcp需要多次握手,具体UDP为什么无法使用,问题还在排查中。