主启动适配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

@@ -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]

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