From 1df6b83184a49370872ad936e4406ef40a5dc0d1 Mon Sep 17 00:00:00 2001 From: zqc <835569504@qq.com> Date: Fri, 27 Feb 2026 12:05:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E5=90=AF=E5=8A=A8=E9=80=82=E9=85=8Dhl?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 32 ++++++++++++++++---------------- main_start.py | 19 +++++++++++++++---- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/config.yaml b/config.yaml index a47bbe9..3354169 100644 --- a/config.yaml +++ b/config.yaml @@ -36,7 +36,7 @@ debug_mode: true service_groups: - name: "kadian_group" # 服务组名称 - video_source_type: "rtsp" + video_source_type: "hls" ws_host: "0.0.0.0" # WebSocket 服务地址 ws_port: 8765 # WebSocket 服务端口 algorithm: "kadian" # 算法类型 @@ -50,18 +50,18 @@ service_groups: - [0.5, 0.001] - [1.0, 0.8] - [0.35, 1.0] -- name: "prison_group" # 服务组名称 - video_source_type: "hls" - ws_host: "0.0.0.0" # WebSocket 服务地址 - ws_port: 8766 # WebSocket 服务端口 - algorithm: "prison" # 算法类型 - cameras: # 该组下的摄像头列表 - - id: 1 - index: testindexcode - name: Entrance - params: - roi_points: - - [0.15, 0.001] - - [0.5, 0.001] - - [1.0, 0.8] - - [0.35, 1.0] +#- name: "prison_group" # 服务组名称 +# video_source_type: "hls" +# ws_host: "0.0.0.0" # WebSocket 服务地址 +# ws_port: 8766 # WebSocket 服务端口 +# algorithm: "prison" # 算法类型 +# cameras: # 该组下的摄像头列表 +# - id: 1 +# index: testindexcode +# name: Entrance +# params: +# roi_points: +# - [0.15, 0.001] +# - [0.5, 0.001] +# - [1.0, 0.8] +# - [0.35, 1.0] diff --git a/main_start.py b/main_start.py index 50dd7e4..a56a4e2 100644 --- a/main_start.py +++ b/main_start.py @@ -94,14 +94,25 @@ def is_process_running(pid: int): return False -def start_rtsp_service(group: dict, script_path: str = "rtsp_service_ws_kadian.py"): - """启动 RTSP 服务子进程(后台运行)""" +def get_script_path(video_source_type: str) -> str: + """根据视频源类型获取对应的服务脚本路径""" + if video_source_type == "hls": + return "hls_service_ws_kadian.py" + else: # 默认 rtsp + return "rtsp_service_ws_kadian.py" + + +def start_service_group(group: dict): + """启动服务子进程(后台运行)""" cameras = group.get("cameras", []) ws_host = group.get("ws_host", "0.0.0.0") ws_port = group.get("ws_port", 8765) algorithm = group.get("algorithm", "") group_name = group.get("name", "default") + video_source_type = group.get("video_source_type", "rtsp") + # 根据视频源类型选择脚本 + script_path = get_script_path(video_source_type) cameras_base64 = cameras_to_base64_json(cameras) cmd = [ @@ -113,7 +124,7 @@ def start_rtsp_service(group: dict, script_path: str = "rtsp_service_ws_kadian.p "--algorithm", algorithm ] - logger.info(f"[INFO] Starting service group '{group_name}': ws={ws_host}:{ws_port}, algorithm={algorithm}") + logger.info(f"[INFO] Starting service group '{group_name}': ws={ws_host}:{ws_port}, algorithm={algorithm}, source={video_source_type}") # DEBUG_MODE=True 时前台运行,方便调试;False 时后台运行,适合部署 if DEBUG_MODE: @@ -149,7 +160,7 @@ def start_service(): continue try: - process, name = start_rtsp_service(group) + process, name = start_service_group(group) time.sleep(0.5) save_pid(process.pid, name) logger.info(f"[INFO] Service group '{name}' started with PID {process.pid}")