Преглед изворни кода

make pre_capture time configurable

Blake Blackshear пре 4 година
родитељ
комит
a8c0fadf95
3 измењених фајлова са 11 додато и 6 уклоњено
  1. 6 1
      config/config.example.yml
  2. 1 1
      detect_objects.py
  3. 4 4
      frigate/events.py

+ 6 - 1
config/config.example.yml

@@ -125,7 +125,12 @@ cameras:
     # WARNING: Videos in /cache are retained until there are no ongoing events. If you are tracking cars or
     # other objects for long periods of time, the cache will continue to grow indefinitely.
     ################
-    save_clips: False
+    save_clips:
+      enabled: False
+      #########
+      # Number of seconds before the event to include in the clips
+      #########
+      pre_capture: 30
 
     ################
     # Configuration for the snapshots in the debug view and mqtt

+ 1 - 1
detect_objects.py

@@ -193,7 +193,7 @@ def main():
         ffmpeg_hwaccel_args = ffmpeg.get('hwaccel_args', FFMPEG_DEFAULT_CONFIG['hwaccel_args'])
         ffmpeg_input_args = ffmpeg.get('input_args', FFMPEG_DEFAULT_CONFIG['input_args'])
         ffmpeg_output_args = ffmpeg.get('output_args', FFMPEG_DEFAULT_CONFIG['output_args'])
-        if config.get('save_clips', False):
+        if config.get('save_clips', {}).get('enabled', False):
             ffmpeg_output_args = [
                 "-f",
                 "segment",

+ 4 - 4
frigate/events.py

@@ -78,7 +78,7 @@ class EventProcessor(threading.Thread):
                 del self.cached_clips[f]
                 os.remove(os.path.join(self.cache_dir,f))
 
-    def create_clip(self, camera, event_data):
+    def create_clip(self, camera, event_data, pre_capture):
         # get all clips from the camera with the event sorted
         sorted_clips = sorted([c for c in self.cached_clips.values() if c['camera'] == camera], key = lambda i: i['start_time'])
 
@@ -88,7 +88,7 @@ class EventProcessor(threading.Thread):
             # get all clips from the camera with the event sorted
             sorted_clips = sorted([c for c in self.cached_clips.values() if c['camera'] == camera], key = lambda i: i['start_time'])
         
-        playlist_start = event_data['start_time']-30
+        playlist_start = event_data['start_time']-pre_capture
         playlist_end = event_data['end_time']+5
         playlist_lines = []
         for clip in sorted_clips:
@@ -145,8 +145,8 @@ class EventProcessor(threading.Thread):
                 self.events_in_process[event_data['id']] = event_data
 
             if event_type == 'end':
-                if self.config[camera].get('save_clips', False) and len(self.cached_clips) > 0:
-                    self.create_clip(camera, event_data)
+                if self.config[camera].get('save_clips', {}).get('enabled', False) and len(self.cached_clips) > 0:
+                    self.create_clip(camera, event_data, self.config[camera].get('save_clips', {}).get('pre_capture', 30))
                 del self.events_in_process[event_data['id']]