界面修改以及显示
This commit is contained in:
39
controller/config_loader.py
Normal file
39
controller/config_loader.py
Normal file
@ -0,0 +1,39 @@
|
||||
import configparser
|
||||
import os
|
||||
|
||||
def load_camera_config(camera_name):
|
||||
"""读取指定摄像头的配置, 并生成RTSP URL"""
|
||||
config = configparser.ConfigParser()
|
||||
# "项目根目录/config/camera_config.ini"
|
||||
config_path = os.path.join(
|
||||
os.path.dirname(os.path.dirname(__file__)), # 项目根目录
|
||||
"config",
|
||||
"camera_config.ini"
|
||||
)
|
||||
# 检查配置文件是否存在
|
||||
if not os.path.exists(config_path):
|
||||
raise FileNotFoundError(f"摄像头配置文件不存在:{config_path}")
|
||||
|
||||
config.read(config_path, encoding="utf-8")
|
||||
|
||||
if camera_name not in config.sections():
|
||||
raise ValueError(f"配置文件中未找到摄像头:{camera_name}")
|
||||
|
||||
# 读取基础配置
|
||||
ip = config.get(camera_name, "ip")
|
||||
port = config.getint(camera_name, "port")
|
||||
username = config.get(camera_name, "username")
|
||||
password = config.get(camera_name, "password")
|
||||
channel = config.get(camera_name, "channel")
|
||||
|
||||
# 生成RTSP URL
|
||||
rtsp_url = f"rtsp://{username}:{password}@{ip}:{port}/streaming/channels/{channel}"
|
||||
|
||||
return {
|
||||
"ip": ip,
|
||||
"port": port,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"channel": channel,
|
||||
"rtsp_url": rtsp_url
|
||||
}
|
||||
Reference in New Issue
Block a user