NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Standardize handling of config files (#15451)
Nicolas Mowen0e3fb6cbddd3
diff --git a/frigate/api/app.py b/frigate/api/app.pyindex 53855efcac..a94c6415ca 100644--- a/frigate/api/app.py+++ b/frigate/api/app.py@@ -21,13 +21,13 @@ from frigate.api.defs.query.app_query_parameters import AppTimelineHourlyQueryPafrom frigate.api.defs.request.app_body import AppConfigSetBodyfrom frigate.api.defs.tags import Tagsfrom frigate.config import FrigateConfig-from frigate.const import CONFIG_DIRfrom frigate.models import Event, Timelinefrom frigate.util.builtin import (clean_camera_user_pass,get_tz_modifiers,update_yaml_from_url,)+from frigate.util.config import find_config_filefrom frigate.util.services import (ffprobe_stream,get_nvidia_driver_info,@@ -147,13 +147,7 @@ def config(request: Request):@router.get("/config/raw")def config_raw():- config_file = os.environ.get("CONFIG_FILE", "/config/config.yml")-- # Check if we can use .yaml instead of .yml- config_file_yaml = config_file.replace(".yml", ".yaml")-- if os.path.isfile(config_file_yaml):- config_file = config_file_yaml+ config_file = find_config_file()if not os.path.isfile(config_file):return JSONResponse(@@ -198,13 +192,7 @@ def config_save(save_option: str, body: Any = Body(media_type="text/plain")):# Save the config to filetry:- config_file = os.environ.get("CONFIG_FILE", "/config/config.yml")-- # Check if we can use .yaml instead of .yml- config_file_yaml = config_file.replace(".yml", ".yaml")-- if os.path.isfile(config_file_yaml):- config_file = config_file_yaml+ config_file = find_config_file()with open(config_file, "w") as f:f.write(new_config)@@ -253,13 +241,7 @@ def config_save(save_option: str, body: Any = Body(media_type="text/plain")):@router.put("/config/set")def config_set(request: Request, body: AppConfigSetBody):- config_file = os.environ.get("CONFIG_FILE", f"{CONFIG_DIR}/config.yml")-- # Check if we can use .yaml instead of .yml- config_file_yaml = config_file.replace(".yml", ".yaml")-- if os.path.isfile(config_file_yaml):- config_file = config_file_yaml+ config_file = find_config_file()with open(config_file, "r") as f:old_raw_config = f.read()diff --git a/frigate/config/config.py b/frigate/config/config.pyindex 8c0b52e92f..770588b932 100644--- a/frigate/config/config.py+++ b/frigate/config/config.py@@ -29,6 +29,7 @@ from frigate.util.builtin import ()from frigate.util.config import (StreamInfoRetriever,+ find_config_file,get_relative_coordinates,migrate_frigate_config,)@@ -67,7 +68,6 @@ logger = logging.getLogger(__name__)yaml = YAML()-DEFAULT_CONFIG_FILE = "/config/config.yml"DEFAULT_CONFIG = """mqtt:enabled: False@@ -638,16 +638,13 @@ class FrigateConfig(FrigateBaseModel):@classmethoddef load(cls, **kwargs):- config_path = os.environ.get("CONFIG_FILE", DEFAULT_CONFIG_FILE)-- if not os.path.isfile(config_path):- config_path = config_path.replace("yml", "yaml")+ config_path = find_config_file()# No configuration file found, create one.new_config = Falseif not os.path.isfile(config_path):logger.info("No config file found, saving default config")- config_path = DEFAULT_CONFIG_FILE+ config_path = config_pathnew_config = Trueelse:# Check if the config file needs to be migrated.diff --git a/frigate/detectors/plugins/rknn.py b/frigate/detectors/plugins/rknn.pyindex dae5cc0576..df94d7b623 100644--- a/frigate/detectors/plugins/rknn.py+++ b/frigate/detectors/plugins/rknn.py@@ -136,17 +136,17 @@ class Rknn(DetectionApi):def check_config(self, config):if (config.model.width != 320) or (config.model.height != 320):raise Exception(- "Make sure to set the model width and height to 320 in your config.yml."+ "Make sure to set the model width and height to 320 in your config.")if config.model.input_pixel_format != "bgr":raise Exception(- 'Make sure to set the model input_pixel_format to "bgr" in your config.yml.'+ 'Make sure to set the model input_pixel_format to "bgr" in your config.')if config.model.input_tensor != "nhwc":raise Exception(- 'Make sure to set the model input_tensor to "nhwc" in your config.yml.'+ 'Make sure to set the model input_tensor to "nhwc" in your config.')def detect_raw(self, tensor_input):diff --git a/frigate/ptz/autotrack.py b/frigate/ptz/autotrack.pyindex 03bb3840e3..9f7f5f1b81 100644--- a/frigate/ptz/autotrack.py+++ b/frigate/ptz/autotrack.py@@ -2,7 +2,6 @@import copyimport logging-import osimport queueimport threadingimport time@@ -29,11 +28,11 @@ from frigate.const import (AUTOTRACKING_ZOOM_EDGE_THRESHOLD,AUTOTRACKING_ZOOM_IN_HYSTERESIS,AUTOTRACKING_ZOOM_OUT_HYSTERESIS,- CONFIG_DIR,)from frigate.ptz.onvif import OnvifControllerfrom frigate.track.tracked_object import TrackedObjectfrom frigate.util.builtin import update_yaml_file+from frigate.util.config import find_config_filefrom frigate.util.image import SharedMemoryFrameManager, intersection_over_unionlogger = logging.getLogger(__name__)@@ -328,13 +327,7 @@ class PtzAutoTracker:self.autotracker_init[camera] = Truedef _write_config(self, camera):- config_file = os.environ.get("CONFIG_FILE", f"{CONFIG_DIR}/config.yml")-- # Check if we can use .yaml instead of .yml- config_file_yaml = config_file.replace(".yml", ".yaml")-- if os.path.isfile(config_file_yaml):- config_file = config_file_yaml+ config_file = find_config_file()logger.debug(f"{camera}: Writing new config with autotracker motion coefficients: {self.config.cameras[camera].onvif.autotracking.movement_weights}"diff --git a/frigate/util/config.py b/frigate/util/config.pyindex 3f3c45aa6b..6bdbc04306 100644--- a/frigate/util/config.py+++ b/frigate/util/config.py@@ -14,6 +14,16 @@ from frigate.util.services import get_video_propertieslogger = logging.getLogger(__name__)CURRENT_CONFIG_VERSION = "0.15-0"+DEFAULT_CONFIG_FILE = "/config/config.yml"+++def find_config_file() -> str:+ config_path = os.environ.get("CONFIG_FILE", DEFAULT_CONFIG_FILE)++ if not os.path.isfile(config_path):+ config_path = config_path.replace("yml", "yaml")++ return config_pathdef migrate_frigate_config(config_file: str):