add post_capture option

This commit is contained in:
Blake Blackshear 2020-12-19 09:06:06 -06:00
parent 24bfe9f3e8
commit 32f5f2cca9
3 changed files with 17 additions and 7 deletions

View File

@ -386,7 +386,9 @@ cameras:
# Required: enables clips for the camera (default: shown below) # Required: enables clips for the camera (default: shown below)
enabled: False enabled: False
# Optional: Number of seconds before the event to include in the clips (default: shown below) # 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) # Optional: Objects to save clips for. (default: all tracked objects)
objects: objects:
- person - 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. - `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 ### 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. - `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.

View File

@ -174,7 +174,8 @@ CAMERAS_SCHEMA = vol.Schema(vol.All(
}, },
vol.Optional('save_clips', default={}): { vol.Optional('save_clips', default={}): {
vol.Optional('enabled', default=False): bool, 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], 'objects': [str],
vol.Optional('retain', default={}): SAVE_CLIPS_RETAIN_SCHEMA, vol.Optional('retain', default={}): SAVE_CLIPS_RETAIN_SCHEMA,
}, },
@ -531,6 +532,7 @@ class CameraSaveClipsConfig():
def __init__(self, global_config, config): def __init__(self, global_config, config):
self._enabled = config['enabled'] self._enabled = config['enabled']
self._pre_capture = config['pre_capture'] self._pre_capture = config['pre_capture']
self._post_capture = config['post_capture']
self._objects = config.get('objects', global_config['objects']['track']) self._objects = config.get('objects', global_config['objects']['track'])
self._retain = SaveClipsRetainConfig(global_config['save_clips']['retain'], config['retain']) self._retain = SaveClipsRetainConfig(global_config['save_clips']['retain'], config['retain'])
@ -541,6 +543,10 @@ class CameraSaveClipsConfig():
@property @property
def pre_capture(self): def pre_capture(self):
return self._pre_capture return self._pre_capture
@property
def post_capture(self):
return self._post_capture
@property @property
def objects(self): def objects(self):
@ -554,6 +560,7 @@ class CameraSaveClipsConfig():
return { return {
'enabled': self.enabled, 'enabled': self.enabled,
'pre_capture': self.pre_capture, 'pre_capture': self.pre_capture,
'post_capture': self.post_capture,
'objects': self.objects, 'objects': self.objects,
'retain': self.retain.to_dict() 'retain': self.retain.to_dict()
} }

View File

@ -97,18 +97,18 @@ class EventProcessor(threading.Thread):
del self.cached_clips[f] del self.cached_clips[f]
os.remove(os.path.join(CACHE_DIR,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 # 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']) 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) time.sleep(5)
self.refresh_cache() self.refresh_cache()
# get all clips from the camera with the event sorted # 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']) 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_start = event_data['start_time']-pre_capture
playlist_end = event_data['end_time']+5 playlist_end = event_data['end_time']+post_capture
playlist_lines = [] playlist_lines = []
for clip in sorted_clips: for clip in sorted_clips:
# clip ends before playlist start time, skip # clip ends before playlist start time, skip
@ -181,7 +181,7 @@ class EventProcessor(threading.Thread):
if event_type == 'end': if event_type == 'end':
if len(self.cached_clips) > 0 and not event_data['false_positive']: 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( Event.create(
id=event_data['id'], id=event_data['id'],
label=event_data['label'], label=event_data['label'],