diff --git a/config/config.example.yml b/config/config.example.yml index 0451746de..90d53ace9 100644 --- a/config/config.example.yml +++ b/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 diff --git a/detect_objects.py b/detect_objects.py index e278ae6a3..5ce2b9edc 100644 --- a/detect_objects.py +++ b/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", diff --git a/frigate/events.py b/frigate/events.py index 3a1c892ac..2ffc09379 100644 --- a/frigate/events.py +++ b/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']] \ No newline at end of file