【发布时间】:2022-11-01 13:31:13
【问题描述】:
我可以使用以下python代码查看局域网上的相机,这不是问题。但是,当从远程站点运行相同的代码时,它会以空帧中断。 VLC播放器可以通过远程连接查看这个网络地址就好了。这是代码:
import os import cv2 os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"]="rtsp_transport;udp|analyzeduration;2000|" os.environ["OPENCV_FFMPEG_DEBUG"] = "1" os.environ["OPENCV_LOG_LEVEL"] = "VERBOSE" x='rtsp://home_routers_ip:cameras_fwded_port/onvif1' cap = cv2.VideoCapture(x,cv2.CAP_FFMPEG) while(cap.isOpened()): ret, frame = cap.read() if ret == False: print("Frame is empty") break; else: cv2.imshow('VIDEO', frame) if cv2.waitKey(20) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()从其工作的家庭 LAN 输出:
[OPENCV:FFMPEG:40] Starting connection attempt to Home_Router's_IP port 42??? [OPENCV:FFMPEG:40] Successfully connected to Home_Router's_IP port 42??? [OPENCV:FFMPEG:40] SDP: v=0 o=- 1421069297525233 1 IN IP4 192.168.1.21 s=H.264 Video, RtspServer_0.0.0.2 t=0 0 a=tool:RtspServer_0.0.0.2 a=type:broadcast a=control:* a=range:npt=0- m=video 0 RTP/AVP 96 c=IN IP4 0.0.0.0 b=AS:500 a=rtpmap:96 H264/90000 a=fmtp:96 packetization-mode=1;profile-level-id=42001F;sprop-parameter-sets=Z0IAH5WoFAFuQA==,aM48gA== a=control:track1 m=audio 0 RTP/AVP 8 a=control:track2 a=rtpmap:8 PCMA/8000 [OPENCV:FFMPEG:40] setting jitter buffer size to 500 [OPENCV:FFMPEG:40] setting jitter buffer size to 500 [OPENCV:FFMPEG:40] max_analyze_duration 2000 reached at 20000 microseconds st:1 [OPENCV:FFMPEG:24] Could not find codec parameters for stream 0 (Video: h264, 1 reference frame, none): unspecified size Consider increasing the value for the 'analyzeduration' (2000) and 'probesize' (5000000) options [OPENCV:FFMPEG:40] Reinit context to 1280x720, pix_fmt: yuv420p WORKING! A live camera window opens up.最后, 从远程站点运行代码时的输出:
[OPENCV:FFMPEG:40] Starting connection attempt to Home_Router's_IP port 42??? [OPENCV:FFMPEG:40] Successfully connected to Home_Router's_IP port 42??? [OPENCV:FFMPEG:40] SDP: v=0 o=- 1421069297525233 1 IN IP4 192.168.1.21 s=H.264 Video, RtspServer_0.0.0.2 t=0 0 a=tool:RtspServer_0.0.0.2 a=type:broadcast a=control:* a=range:npt=0- m=video 0 RTP/AVP 96 c=IN IP4 0.0.0.0 b=AS:500 a=rtpmap:96 H264/90000 a=fmtp:96 packetization-mode=1;profile-level-id=42001F;sprop-parameter-sets=Z0IAH5WoFAFuQA==,aM48gA== a=control:track1 m=audio 0 RTP/AVP 8 a=control:track2 a=rtpmap:8 PCMA/8000 [OPENCV:FFMPEG:40] setting jitter buffer size to 500 [OPENCV:FFMPEG:40] setting jitter buffer size to 500 [OPENCV:FFMPEG:24] Could not find codec parameters for stream 0 (Video: h264, 1 reference frame, none): unspecified size Consider increasing the value for the 'analyzeduration' (2000) and 'probesize' (5000000) options Frame is empty PROGRAM Aborts :(
【问题讨论】:
-
你如何从远程使用 vlc 访问它?
-
如果你在阅读之前
sleep会发生什么?可能尚未捕获任何帧。 -
从远程访问 Micka vlc 与本地、ctrl/command N 和粘贴 rtsp url 没有什么不同。 Kesh,测试了在阅读前添加睡眠,没有区别。
-
问题似乎是这条线'o = - 1421069297525233 1 IN IP4 192.168.1.21' A tcpdump 输出显示'cap = cv2.VideoCapture(x,cv2.CAP_FFMPEG)'正在将udp数据报发送到192.168.1.21(而不是home_routers_ip:cameras_fwded_port ),这恰好是本地 LAN 上的 rtsp 服务器地址。如果从本地局域网访问一切都很好,但远程它没有意义。