主启动适配hls

This commit is contained in:
zqc
2026-02-27 12:05:44 +08:00
parent a72b8116a5
commit 1df6b83184
2 changed files with 31 additions and 20 deletions

View File

@@ -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}")