Skip to content

Commit

Permalink
make pre_capture time configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Aug 1, 2020
1 parent 6dc7b8f commit a8c0fad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion detect_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def on_connect(client, userdata, flags, rc):
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",
Expand Down
8 changes: 4 additions & 4 deletions frigate/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def refresh_cache(self):
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'])

Expand All @@ -88,7 +88,7 @@ def create_clip(self, camera, event_data):
# 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:
Expand Down Expand Up @@ -145,8 +145,8 @@ def run(self):
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']]


0 comments on commit a8c0fad

Please sign in to comment.