Skip to content

Commit

Permalink
add post_capture option
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Jan 27, 2021
1 parent af8594c commit f20e1f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.


Expand Down
9 changes: 8 additions & 1 deletion frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def ensure_zones_and_cameras_have_different_names(cameras):
},
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,
},
Expand Down Expand Up @@ -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'])

Expand All @@ -541,6 +543,10 @@ def enabled(self):
@property
def pre_capture(self):
return self._pre_capture

@property
def post_capture(self):
return self._post_capture

@property
def objects(self):
Expand All @@ -554,6 +560,7 @@ def to_dict(self):
return {
'enabled': self.enabled,
'pre_capture': self.pre_capture,
'post_capture': self.post_capture,
'objects': self.objects,
'retain': self.retain.to_dict()
}
Expand Down
8 changes: 4 additions & 4 deletions frigate/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ def refresh_cache(self):
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
Expand Down Expand Up @@ -181,7 +181,7 @@ def run(self):

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'],
Expand Down

0 comments on commit f20e1f2

Please sign in to comment.