我有 4 个无名 ip 摄像头,在捕获 rtsp 流时遇到问题。随机输出文件甚至没有创建。我正在通过 ffmpeg 捕获流。在 Ubuntu Server 18.04 上尝试使用 snap ffmpeg,在 Debian 7 上尝试使用普通 ffmpeg。同样的麻烦。
(/snap/bin/ffmpeg -y -use_wallclock_as_timestamps 1 -hide_banner -loglevel trace -i rtsp://192.168.0.16$1:554/11 -c:v copy -an -flags +global_header $VIDEO_FILE 2> $LOG_FOLDER/cam$1 ) &
尝试过-日志级别调试但它只显示成功的 RTSP 连接,仅此而已。和-日志级别跟踪我注意到成功和失败过程之间的区别。
Error: unable to open display
Splitting the commandline.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-use_wallclock_as_timestamps' ... matched as AVOption 'use_wallclock_as_timestamps' with argument '1'.
Reading option '-hide_banner' ... matched as option 'hide_banner' (do not show program banner) with argument '1'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'trace'.
Reading option '-i' ... matched as input url with argument 'rtsp://192.168.0.161:554/11'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-an' ... matched as option 'an' (disable audio) with argument '1'.
Reading option '-flags' ... matched as AVOption 'flags' with argument '+global_header'.
Reading option '/home/melo/samba/video/19-03-07/cam1/16-06-11.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option hide_banner (do not show program banner) with argument 1.
Applying option loglevel (set logging level) with argument trace.
Successfully parsed a group of options.
Parsing a group of options: input url rtsp://192.168.0.161:554/11.
Successfully parsed a group of options.
Opening an input file: rtsp://192.168.0.161:554/11.
Probing rtsp score:100 size:0
[tcp @ 0x1b5cc40] No default whitelist set
[tcp @ 0x1b5cc40] Original list of addresses:
[tcp @ 0x1b5cc40] Address 192.168.0.161 port 554
[tcp @ 0x1b5cc40] Interleaved list of addresses:
[tcp @ 0x1b5cc40] Address 192.168.0.161 port 554
[tcp @ 0x1b5cc40] Starting connection attempt to 192.168.0.161 port 554
[tcp @ 0x1b5cc40] Successfully connected to 192.168.0.161 port 554
[rtsp @ 0x1b5abc0] Sending:
OPTIONS rtsp://192.168.0.161:554/11 RTSP/1.0
CSeq: 1
User-Agent: Lavf58.20.100
--
[rtsp @ 0x1b5abc0] ret=1 c=52 [R]
[rtsp @ 0x1b5abc0] ret=1 c=54 [T]
[rtsp @ 0x1b5abc0] ret=1 c=53 [S]
[rtsp @ 0x1b5abc0] ret=1 c=50 [P]
[rtsp @ 0x1b5abc0] ret=1 c=2f [/]
[rtsp @ 0x1b5abc0] ret=1 c=31 [1]
[rtsp @ 0x1b5abc0] ret=1 c=2e [.]
[rtsp @ 0x1b5abc0] ret=1 c=30 [0]
[rtsp @ 0x1b5abc0] ret=1 c=20 [ ]
[rtsp @ 0x1b5abc0] ret=1 c=32 [2]
[rtsp @ 0x1b5abc0] ret=1 c=30 [0]
Last message repeated 1 times
[rtsp @ 0x1b5abc0] ret=1 c=20 [ ]
[rtsp @ 0x1b5abc0] ret=1 c=4f [O]
[rtsp @ 0x1b5abc0] ret=1 c=4b [K]
[rtsp @ 0x1b5abc0] ret=1 c=0d [
]
[rtsp @ 0x1b5abc0] ret=1 c=0a [
]
[rtsp @ 0x1b5abc0] line='RTSP/1.0 200 OK'
[rtsp @ 0x1b5abc0] ret=1 c=43 [C]
[rtsp @ 0x1b5abc0] ret=1 c=53 [S]
[rtsp @ 0x1b5abc0] ret=1 c=65 [e]
[rtsp @ 0x1b5abc0] ret=1 c=71 [q]
[rtsp @ 0x1b5abc0] ret=1 c=3a [:]
[rtsp @ 0x1b5abc0] ret=1 c=20 [ ]
[rtsp @ 0x1b5abc0] ret=1 c=31 [1]
[rtsp @ 0x1b5abc0] ret=1 c=0d [
]
[rtsp @ 0x1b5abc0] ret=1 c=0a [
]
良好的编码和成功过程中的一切都很清晰。
Error: unable to open display
Splitting the commandline.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-use_wallclock_as_timestamps' ... matched as AVOption 'use_wallclock_as_timestamps' with argument '1'.
Reading option '-hide_banner' ... matched as option 'hide_banner' (do not show program banner) with argument '1'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'trace'.
Reading option '-i' ... matched as input url with argument 'rtsp://192.168.0.163:554/11'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-an' ... matched as option 'an' (disable audio) with argument '1'.
Reading option '-flags' ... matched as AVOption 'flags' with argument '+global_header'.
Reading option '/home/melo/samba/video/19-03-07/cam3/16-06-11.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option hide_banner (do not show program banner) with argument 1.
Applying option loglevel (set logging level) with argument trace.
Successfully parsed a group of options.
Parsing a group of options: input url rtsp://192.168.0.163:554/11.
Successfully parsed a group of options.
Opening an input file: rtsp://192.168.0.163:554/11.
Probing rtsp score:100 size:0
[tcp @ 0x18eec40] No default whitelist set
[tcp @ 0x18eec40] Original list of addresses:
[tcp @ 0x18eec40] Address 192.168.0.163 port 554
[tcp @ 0x18eec40] Interleaved list of addresses:
[tcp @ 0x18eec40] Address 192.168.0.163 port 554
[tcp @ 0x18eec40] Starting connection attempt to 192.168.0.163 port 554
[tcp @ 0x18eec40] Successfully connected to 192.168.0.163 port 554
[rtsp @ 0x18ecbc0] Sending:
OPTIONS rtsp://192.168.0.163:554/11 RTSP/1.0
CSeq: 1
User-Agent: Lavf58.20.100
--
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=08 []
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=04 [?]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=01 [?]
[rtsp @ 0x18ecbc0] ret=1 c=48 [H]
[rtsp @ 0x18ecbc0] ret=1 c=02 [?]
[rtsp @ 0x18ecbc0] ret=1 c=2a [*]
[rtsp @ 0x18ecbc0] ret=1 c=e0 [à]
[rtsp @ 0x18ecbc0] ret=1 c=bc [Œ]
[rtsp @ 0x18ecbc0] ret=1 c=84 []
[rtsp @ 0x18ecbc0] ret=1 c=c0 [À]
[rtsp @ 0x18ecbc0] ret=1 c=a8 [š]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=a3 [£]
[rtsp @ 0x18ecbc0] ret=1 c=ff [ÿ]
Last message repeated 9 times
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=08 []
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=04 [?]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=01 [?]
[rtsp @ 0x18ecbc0] ret=1 c=48 [H]
[rtsp @ 0x18ecbc0] ret=1 c=02 [?]
[rtsp @ 0x18ecbc0] ret=1 c=2a [*]
[rtsp @ 0x18ecbc0] ret=1 c=e0 [à]
[rtsp @ 0x18ecbc0] ret=1 c=bc [Œ]
[rtsp @ 0x18ecbc0] ret=1 c=84 []
[rtsp @ 0x18ecbc0] ret=1 c=c0 [À]
[rtsp @ 0x18ecbc0] ret=1 c=a8 [š]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=a3 [£]
[rtsp @ 0x18ecbc0] ret=1 c=ff [ÿ]
Last message repeated 9 times
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=08 []
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=04 [?]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=01 [?]
[rtsp @ 0x18ecbc0] ret=1 c=48 [H]
[rtsp @ 0x18ecbc0] ret=1 c=02 [?]
[rtsp @ 0x18ecbc0] ret=1 c=2a [*]
[rtsp @ 0x18ecbc0] ret=1 c=e0 [à]
[rtsp @ 0x18ecbc0] ret=1 c=bc [Œ]
[rtsp @ 0x18ecbc0] ret=1 c=84 []
[rtsp @ 0x18ecbc0] ret=1 c=c0 [À]
[rtsp @ 0x18ecbc0] ret=1 c=a8 [š]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=a3 [£]
[rtsp @ 0x18ecbc0] ret=1 c=ff [ÿ]
Last message repeated 9 times
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=08 []
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=04 [?]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=01 [?]
[rtsp @ 0x18ecbc0] ret=1 c=48 [H]
[rtsp @ 0x18ecbc0] ret=1 c=02 [?]
[rtsp @ 0x18ecbc0] ret=1 c=2a [*]
[rtsp @ 0x18ecbc0] ret=1 c=e0 [à]
[rtsp @ 0x18ecbc0] ret=1 c=bc [Œ]
[rtsp @ 0x18ecbc0] ret=1 c=84 []
[rtsp @ 0x18ecbc0] ret=1 c=c0 [À]
[rtsp @ 0x18ecbc0] ret=1 c=a8 [š]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=a3 [£]
[rtsp @ 0x18ecbc0] ret=1 c=ff [ÿ]
Last message repeated 9 times
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=08 []
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=04 [?]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=01 [?]
[rtsp @ 0x18ecbc0] ret=1 c=48 [H]
[rtsp @ 0x18ecbc0] ret=1 c=02 [?]
[rtsp @ 0x18ecbc0] ret=1 c=2a [*]
[rtsp @ 0x18ecbc0] ret=1 c=e0 [à]
[rtsp @ 0x18ecbc0] ret=1 c=bc [Œ]
[rtsp @ 0x18ecbc0] ret=1 c=84 []
[rtsp @ 0x18ecbc0] ret=1 c=c0 [À]
[rtsp @ 0x18ecbc0] ret=1 c=a8 [š]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=a3 [£]
[rtsp @ 0x18ecbc0] ret=1 c=ff [ÿ]
Last message repeated 9 times
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=08 []
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=06 [?]
[rtsp @ 0x18ecbc0] ret=1 c=04 [?]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=01 [?]
[rtsp @ 0x18ecbc0] ret=1 c=48 [H]
[rtsp @ 0x18ecbc0] ret=1 c=02 [?]
[rtsp @ 0x18ecbc0] ret=1 c=2a [*]
[rtsp @ 0x18ecbc0] ret=1 c=e0 [à]
[rtsp @ 0x18ecbc0] ret=1 c=bc [Œ]
[rtsp @ 0x18ecbc0] ret=1 c=84 []
[rtsp @ 0x18ecbc0] ret=1 c=c0 [À]
[rtsp @ 0x18ecbc0] ret=1 c=a8 [š]
[rtsp @ 0x18ecbc0] ret=1 c=00 [[rtsp @ 0x18ecbc0] ret=1 c=a3 [£]
[rtsp @ 0x18ecbc0] ret=1 c=ff [ÿ]
Last message repeated 9 times
看起来像个狗屎。
日志文件不完整,但我认为已经足够了。这会随随机摄像头随机出现。
如何修复它?
答案1
我自己找到了解决方案。我遇到的问题是数据包的真实性。我尝试添加强制 tcp 连接标志(-rtsp_传输 TCP)并且它有效。没问题了。