Add object detection, tracking, mobile notifications, and search to any security camera.
new export
Rory Clear70bc5b43e468
diff --git a/utils/helpers.py b/utils/helpers.pyindex 59c0ee8..73402a1 100644--- a/utils/helpers.py+++ b/utils/helpers.py@@ -141,63 +141,33 @@ def export_clip(stream_dir, output_path: Path, live=False, length=5, end=0, starwith open(concat_list_path, "w") as f: f.writelines(f"file '{segment.resolve()}'\n" for segment in recent_segments)output_path.parent.mkdir(parents=True, exist_ok=True)ffmpeg_path = find_ffmpeg()- if live:+ with open(stream_dir / "concat_list.txt", "r") as f: print(" ".join(line.strip() for line in f)) # todo+ crf = 32+ while True:command = [ffmpeg_path,"-y","-f", "concat","-safe", "0","-i", str(concat_list_path),- "-loglevel", "quiet",- "-vf", "scale=-2:240,fps=24,format=yuv420p",+ *(["-vf", "scale=-2:240,fps=24,format=yuv420p", "-preset", "veryslow",] if live else []),"-c:v", "libx264","-pix_fmt", "yuv420p","-preset", "veryslow",- "-crf", "32",+ "-crf", str(crf),"-an",str(output_path)]subprocess.run(command, check=True)- else:- with open(stream_dir / "concat_list.txt", "r") as f: print(" ".join(line.strip() for line in f))- command = [- ffmpeg_path,- "-y",- "-f", "concat",- "-safe", "0",- "-i", str(concat_list_path),- "-c:v", "libx264",- "-crf", "18",- "-pix_fmt", "yuv420p",- "-an", # No audio- str(output_path)- ]- subprocess.run(command, check=True)- comp = 5+ crf += 5file_size = 10*1024*1024with open(output_path, "rb") as f:file_data = f.read()file_size = len(file_data)- while file_size >= 9*1024*1024: # max size 10MB, # todo, calculate time from ts files- temp_output = output_path.with_stem(output_path.stem + "_compressed")- command = [- ffmpeg_path,- "-y",- "-f", "concat",- "-safe", "0",- "-i", str(concat_list_path),- "-c:v", "libx264",- "-crf", str(18 + comp),- "-pix_fmt", "yuv420p", # needed for android- "-an", # No audio- str(temp_output)- ]- subprocess.run(command, check=True)- os.replace(temp_output, output_path)- with open(output_path, "rb") as f:- file_data = f.read()- file_size = len(file_data)- comp += 5+ if file_size <= 9*1024*1024:+ break # max size 10MB, # todo, calculate time from ts files+ else:+ crf += 5def export_and_upload(cam_name, thumbnail, userID, key, start=None, end=0, length=20, wait=False):if wait: time.sleep(10) # todo, objects can be too far ahead