Add per camera directory support

This commit is contained in:
Michael Wei 2020-11-14 09:30:37 +00:00
parent 893e6b40a7
commit 892668640c
2 changed files with 12 additions and 3 deletions

View File

@ -183,6 +183,10 @@ save_clips:
# Optional: Location to save cache files for creating clips. (default: shown below) # 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. # NOTE: To reduce wear on SSDs and SD cards, use a tmpfs volume.
cache_dir: /cache 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 # Optional: Global ffmpeg args
# "ffmpeg" + global_args + input_args + "-i" + input + output_args # "ffmpeg" + global_args + input_args + "-i" + input + output_args

View File

@ -112,7 +112,12 @@ class EventProcessor(threading.Thread):
if clip['start_time']+clip['duration'] > playlist_end: if clip['start_time']+clip['duration'] > playlist_end:
playlist_lines.append(f"outpoint {int(playlist_end-clip['start_time'])}") 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_cmd = [
'ffmpeg', 'ffmpeg',
'-y', '-y',
@ -126,7 +131,7 @@ class EventProcessor(threading.Thread):
'-', '-',
'-c', '-c',
'copy', '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) 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) print(p.stderr)
return 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) json.dump(event_data, outfile)
def run(self): def run(self):