From 892668640c5cb0b98f5c2ee1779f1ad8497f4e80 Mon Sep 17 00:00:00 2001 From: Michael Wei Date: Sat, 14 Nov 2020 09:30:37 +0000 Subject: [PATCH] Add per camera directory support --- README.md | 4 ++++ frigate/events.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index af6aa219a..a5a2bcfed 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,10 @@ save_clips: # Optional: Location to save cache files for creating clips. (default: shown below) # NOTE: To reduce wear on SSDs and SD cards, use a tmpfs volume. cache_dir: /cache + # Optional: Create a per camera directory for saved clips (default: false) + # set to true for per camera dir named after the camera, + # false for clips all in the same directory + per_camera_dir: False # Optional: Global ffmpeg args # "ffmpeg" + global_args + input_args + "-i" + input + output_args diff --git a/frigate/events.py b/frigate/events.py index 6b4785c3f..3ed286f45 100644 --- a/frigate/events.py +++ b/frigate/events.py @@ -112,7 +112,12 @@ class EventProcessor(threading.Thread): if clip['start_time']+clip['duration'] > playlist_end: playlist_lines.append(f"outpoint {int(playlist_end-clip['start_time'])}") - clip_name = f"{camera}-{event_data['id']}" + per_camera_dir = self.config.get('save_clips', {}).get('per_camera_dir', False) + if per_camera_dir: + os.makedirs(os.path.join(self.clip_dir, camera), exist_ok=True) + clip_name = os.path.join(camera, f"{event_data['id']}") if per_camera_dir else f"{camera}-{event_data['id']}" + clip_path = os.path.join(self.clip_dir, clip_name) + ffmpeg_cmd = [ 'ffmpeg', '-y', @@ -126,7 +131,7 @@ class EventProcessor(threading.Thread): '-', '-c', 'copy', - f"{os.path.join(self.clip_dir, clip_name)}.mp4" + f"{clip_path}.mp4" ] p = sp.run(ffmpeg_cmd, input="\n".join(playlist_lines), encoding='ascii', capture_output=True) @@ -134,7 +139,7 @@ class EventProcessor(threading.Thread): print(p.stderr) return - with open(f"{os.path.join(self.clip_dir, clip_name)}.json", 'w') as outfile: + with open(f"{clip_path}.json", 'w') as outfile: json.dump(event_data, outfile) def run(self):