Explorar el Código

feat(视频流): 添加RTSP视频流启动失败时的备选方案

当RTSP视频流启动失败时,尝试使用SDK方式启动视频流。同时优化RTSP URL的获取逻辑,优先使用配置中的rtsp_url。
wenhongquan hace 4 días
padre
commit
cd917825b2
Se han modificado 2 ficheros con 8 adiciones y 11 borrados
  1. 6 0
      dual_camera_system/main.py
  2. 2 11
      dual_camera_system/panorama_camera.py

+ 6 - 0
dual_camera_system/main.py

@@ -205,6 +205,12 @@ class DualCameraSystem:
             self.panorama_camera.disconnect()
             return False
         
+        # 启动视频流获取帧数据
+        if not self.panorama_camera.start_stream_rtsp():
+            logger.warning("RTSP视频流启动失败,尝试SDK方式...")
+            if not self.panorama_camera.start_stream():
+                logger.error("无法启动视频流,校准可能无法获取画面")
+        
         # 创建校准器 - 支持视觉检测
         self.calibrator = CameraCalibrator(
             ptz_camera=self.ptz_camera,

+ 2 - 11
dual_camera_system/panorama_camera.py

@@ -117,16 +117,8 @@ class PanoramaCamera:
         return True
     
     def start_stream_rtsp(self, rtsp_url: str = None) -> bool:
-        """
-        通过RTSP协议获取视频流
-        Args:
-            rtsp_url: RTSP地址,格式: rtsp://user:pass@ip:port/channel
-        Returns:
-            是否成功
-        """
         if rtsp_url is None:
-            # 构建RTSP地址
-            rtsp_url = f"rtsp://{self.config['username']}:{self.config['password']}@{self.config['ip']}:{self.config.get('rtsp_port', 554)}/h264/ch{self.config['channel']}/main/av_stream"
+            rtsp_url = self.config.get('rtsp_url') or f"rtsp://{self.config['username']}:{self.config['password']}@{self.config['ip']}:{self.config.get('rtsp_port', 554)}/h264/ch{self.config['channel']}/main/av_stream"
         
         try:
             self.rtsp_cap = cv2.VideoCapture(rtsp_url)
@@ -212,8 +204,7 @@ class PanoramaCamera:
                 time.sleep(0.1)
     
     def _build_rtsp_url(self) -> str:
-        """构建 RTSP URL"""
-        return f"rtsp://{self.config['username']}:{self.config['password']}@{self.config['ip']}:{self.config.get('rtsp_port', 554)}/h264/ch{self.config['channel']}/main/av_stream"
+        return self.config.get('rtsp_url') or f"rtsp://{self.config['username']}:{self.config['password']}@{self.config['ip']}:{self.config.get('rtsp_port', 554)}/h264/ch{self.config['channel']}/main/av_stream"
     
     def _rtsp_stream_worker(self):
         """RTSP视频流工作线程"""