Add object detection, tracking, mobile notifications, and search to any security camera.
maybe does aes
roryclearb38495ffecd8
diff --git a/experimental/clearcam_rtsp.py b/experimental/clearcam_rtsp.pyindex b7890c4..44a1344 100644--- a/experimental/clearcam_rtsp.py+++ b/experimental/clearcam_rtsp.py@@ -24,6 +24,12 @@ from datetime import datetime, time as time_objimport uuidfrom collections import deque+from pathlib import Path+from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes+from cryptography.hazmat.primitives import padding+from cryptography.hazmat.backends import default_backend+import secrets+#Model architecture from https://github.com/ultralytics/ultralytics/issues/189#The upsampling class has been taken from this pull request https://github.com/tinygrad/tinygrad/pull/784 by dc-dc-dc. Now 2(?) models use upsampling. (retinet and this)@@ -456,6 +462,7 @@ class VideoCapture:os.makedirs("event_clips", exist_ok=True)mp4_filename = f"event_clips/{datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}.mp4"self.streamer.export_last_segments(Path(mp4_filename))+ encrypt_file(Path(mp4_filename), Path("{datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}.mp4.aes"), "your-32-byte-encryption-key-here")send_det = Falsewith self.lock:self.raw_frame = frame.copy()@@ -465,6 +472,7 @@ class VideoCapture:print("Error in capture_loop:", e)self._open_ffmpeg()time.sleep(1)+def inference_loop(self):prev_time = time.time()@@ -521,7 +529,7 @@ class HLSStreamer:if not self.output_dir.exists(): self.output_dir.mkdir()def _get_new_stream_dir(self):- timestamp = datetime.now().strftime("%Y-%m-%d_%H:%M:%S") # todo ios format+ timestamp = datetime.now().strftime("%Y-%m-%d_%H:%M:%S")stream_dir = self.output_dir / timestampself.cam.dir = stream_dirstream_dir.mkdir(exist_ok=True)@@ -731,6 +739,29 @@ def send_notif(session_token: str):finally:conn.close()+MAGIC_NUMBER = 0x4D41474943+HEADER_SIZE = 8+AES_BLOCK_SIZE = 16+AES_KEY_SIZE = 32+def encrypt_file(input_path: Path, output_path: Path, key: str):+ key_bytes = key.encode('utf-8')+ with open(input_path, 'rb') as f: plaintext = f.read()+ header = MAGIC_NUMBER.to_bytes(HEADER_SIZE, byteorder='big')+ data_to_encrypt = header + plaintext+ iv = secrets.token_bytes(AES_BLOCK_SIZE)+ padder = padding.PKCS7(AES_BLOCK_SIZE * 8).padder()+ padded_data = padder.update(data_to_encrypt) + padder.finalize()+ cipher = Cipher(+ algorithms.AES(key_bytes),+ modes.CBC(iv),+ backend=default_backend()+ )+ encryptor = cipher.encryptor()+ ciphertext = encryptor.update(padded_data) + encryptor.finalize()+ with open(output_path, 'wb') as f:+ f.write(iv)+ f.write(ciphertext)+class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):"""Serve HTTP requests in separate threads."""