Ver código fonte

use global and ensure dirs exist

Blake Blackshear 4 anos atrás
pai
commit
939d1ba091
1 arquivos alterados com 10 adições e 6 exclusões
  1. 10 6
      detect_objects.py

+ 10 - 6
detect_objects.py

@@ -35,6 +35,14 @@ elif CONFIG_FILE.endswith(".json"):
     with open(CONFIG_FILE) as f:
         CONFIG = json.load(f)
 
+CACHE_DIR = CONFIG.get('save_clips', {}).get('cache_dir', '/cache')
+CLIPS_DIR = CONFIG.get('save_clips', {}).get('clips_dir', '/cache')
+
+if not os.path.exists(CACHE_DIR):
+    os.makedirs(CACHE_DIR)
+if not os.path.exists(CLIPS_DIR):
+    os.makedirs(CLIPS_DIR)
+
 MQTT_HOST = CONFIG['mqtt']['host']
 MQTT_PORT = CONFIG.get('mqtt', {}).get('port', 1883)
 MQTT_TOPIC_PREFIX = CONFIG.get('mqtt', {}).get('topic_prefix', 'frigate')
@@ -214,7 +222,6 @@ def main():
         if not config.get('fps') is None:
             ffmpeg_output_args = ["-r", str(config.get('fps'))] + ffmpeg_output_args
         if config.get('save_clips', {}).get('enabled', False):
-            cache_dir = config.get('save_clips', {}).get('cache_dir', '/cache')
             ffmpeg_output_args = [
                 "-f",
                 "segment",
@@ -231,7 +238,7 @@ def main():
                 "-an",
                 "-map",
                 "0",
-                f"{os.path.join(cache_dir, name)}-%Y%m%d%H%M%S.mp4"
+                f"{os.path.join(CACHE_DIR, name)}-%Y%m%d%H%M%S.mp4"
             ] + ffmpeg_output_args
         ffmpeg_cmd = (['ffmpeg'] +
                 ffmpeg_global_args +
@@ -297,10 +304,7 @@ def main():
         camera_process['process'].start()
         print(f"Camera_process started for {name}: {camera_process['process'].pid}")
 
-
-    cache_dir = config.get('save_clips', {}).get('cache_dir', '/cache')
-    clips_dir = config.get('save_clips', {}).get('clips_dir', '/clips')
-    event_processor = EventProcessor(CONFIG, camera_processes, cache_dir, clips_dir, event_queue, stop_event)
+    event_processor = EventProcessor(CONFIG, camera_processes, CACHE_DIR, CLIPS_DIR, event_queue, stop_event)
     event_processor.start()
     
     object_processor = TrackedObjectProcessor(CONFIG['cameras'], client, MQTT_TOPIC_PREFIX, tracked_objects_queue, event_queue, stop_event)