我自己在使用SRS服务的Ingest功能时发现在读取一个网络摄像头的RTSP流时一直不成功,
具体分析后发现SRS在调用FFmpeg时出了问题:
/usr/local/ffmpeg/bin/ffmpeg -i rtsp://admin:admin123@192.168.50.187:554/profile1 -vcodec copy -acodec copy -f flv -y rtmp://192.168.50.212/live/test
报错如下:
[rtsp @ 0x55842477d740] UDP timeout, retrying with TCP
[rtsp @ 0x55842477d740] method SETUP failed: 404 Unknown Error!
[rtsp @ 0x55842477d740] Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://admin:admin123@192.168.50.187:554/profile1':
Metadata:
title : profile1
Duration: N/A, start: 0.000000, bitrate: 64 kb/s
Stream #0:0: Video: h264, none, 90k tbr, 90k tbn, 180k tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
Output #0, flv, to 'rtmp://192.168.50.212/live/test':
Metadata:
title : profile1
encoder : Lavf58.27.103
Stream #0:0: Audio: pcm_alaw ([7][0][0][0] / 0x0007), 8000 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
[flv @ 0x5584247e5a00] Failed to update header with correct duration.
[flv @ 0x5584247e5a00] Failed to update header with correct filesize.
size= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
在网上搜了一下,发现命令中强制使用TCP链接就不会报错:
/usr/local/ffmpeg/bin/ffmpeg -rtsp_transport tcp -i rtsp://admin:admin123@192.168.50.187:554/profile1 -vcodec copy -acodec copy -f flv -y rtmp://192.168.50.212/live/test
但是搜了半天也没人解释的清楚为什么,暂且找到相关的两篇记录下来: