From 32f5f2cca9e82ebed582289ab742f59f797308ea Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sat, 19 Dec 2020 09:06:06 -0600 Subject: [PATCH] add post_capture option --- README.md | 7 +++++-- frigate/config.py | 9 ++++++++- frigate/events.py | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d564ee44c..99accc5e5 100644 --- a/README.md +++ b/README.md @@ -386,7 +386,9 @@ cameras: # Required: enables clips for the camera (default: shown below) enabled: False # Optional: Number of seconds before the event to include in the clips (default: shown below) - pre_capture: 30 + pre_capture: 5 + # Optional: Number of seconds after the event to include in the clips (default: shown below) + post_capture: 5 # Optional: Objects to save clips for. (default: all tracked objects) objects: - person @@ -653,7 +655,8 @@ Event and clip information is managed in a sqlite database at `/media/frigate/cl - `max_seconds`: This limits the size of the cache when an object is being tracked. If an object is stationary and being tracked for a long time, the cache files will expire and this value will be the maximum clip length for the *end* of the event. For example, if this is set to 300 seconds and an object is being tracked for 600 seconds, the clip will end up being the last 300 seconds. Defaults to 300 seconds. ### Per-camera Configuration Options -- `pre_capture`: Defines how much time should be included in the clip prior to the beginning of the event. Defaults to 30 seconds. +- `pre_capture`: Defines how much time should be included in the clip prior to the beginning of the event. Defaults to 5 seconds. +- `post_capture`: Defines how much time should be included in the clip after the end of the event. Defaults to 5 seconds. - `objects`: List of object types to save clips for. Object types here must be listed for tracking at the camera or global configuration. Defaults to all tracked objects. diff --git a/frigate/config.py b/frigate/config.py index 7001450bd..2482d9ebe 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -174,7 +174,8 @@ CAMERAS_SCHEMA = vol.Schema(vol.All( }, vol.Optional('save_clips', default={}): { vol.Optional('enabled', default=False): bool, - vol.Optional('pre_capture', default=30): int, + vol.Optional('pre_capture', default=5): int, + vol.Optional('post_capture', default=5): int, 'objects': [str], vol.Optional('retain', default={}): SAVE_CLIPS_RETAIN_SCHEMA, }, @@ -531,6 +532,7 @@ class CameraSaveClipsConfig(): def __init__(self, global_config, config): self._enabled = config['enabled'] self._pre_capture = config['pre_capture'] + self._post_capture = config['post_capture'] self._objects = config.get('objects', global_config['objects']['track']) self._retain = SaveClipsRetainConfig(global_config['save_clips']['retain'], config['retain']) @@ -541,6 +543,10 @@ class CameraSaveClipsConfig(): @property def pre_capture(self): return self._pre_capture + + @property + def post_capture(self): + return self._post_capture @property def objects(self): @@ -554,6 +560,7 @@ class CameraSaveClipsConfig(): return { 'enabled': self.enabled, 'pre_capture': self.pre_capture, + 'post_capture': self.post_capture, 'objects': self.objects, 'retain': self.retain.to_dict() } diff --git a/frigate/events.py b/frigate/events.py index 8b8053474..ca6a3fad0 100644 --- a/frigate/events.py +++ b/frigate/events.py @@ -97,18 +97,18 @@ class EventProcessor(threading.Thread): del self.cached_clips[f] os.remove(os.path.join(CACHE_DIR,f)) - def create_clip(self, camera, event_data, pre_capture): + def create_clip(self, camera, event_data, pre_capture, post_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']) - while sorted_clips[-1]['start_time'] + sorted_clips[-1]['duration'] < event_data['end_time']: + while sorted_clips[-1]['start_time'] + sorted_clips[-1]['duration'] < event_data['end_time']+post_capture: time.sleep(5) self.refresh_cache() # 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']-pre_capture - playlist_end = event_data['end_time']+5 + playlist_end = event_data['end_time']+post_capture playlist_lines = [] for clip in sorted_clips: # clip ends before playlist start time, skip @@ -181,7 +181,7 @@ class EventProcessor(threading.Thread): if event_type == 'end': if len(self.cached_clips) > 0 and not event_data['false_positive']: - self.create_clip(camera, event_data, save_clips_config.pre_capture) + self.create_clip(camera, event_data, save_clips_config.pre_capture, save_clips_config.post_capture) Event.create( id=event_data['id'], label=event_data['label'],