-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_service.py
62 lines (48 loc) · 1.7 KB
/
storage_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from config import Config
import logging
import time
import cv2
import os
fourcc = cv2.VideoWriter_fourcc("m", "p", "4", "v")
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] [%(module)s:%(funcName)s:%(lineno)d] - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
# Function to store video data
def store_video_data(frames, camera_id, fps):
"""
Store segmented and compressed video data to a designated storage location.
Args:
frames: The frame data to be stored.
camera_id (int): The ID of the camera.
fps (int): Frames per second.
Returns:
None
Stores the segmented and compressed video data to the specified storage location or file system.
"""
try:
storage_path = f"storage/camera_{camera_id}/"
current_date = time.strftime("%Y-%m-%d")
current_time = time.strftime("%H-%M-%S")
filename = f"video_{current_date}_{current_time}.mp4"
logging.info(
f"Storing video data for stream {camera_id} at: {storage_path + filename}"
)
os.makedirs(storage_path, exist_ok=True)
out = cv2.VideoWriter(
storage_path + filename,
fourcc,
fps,
(Config.FRAME_WIDTH, Config.FRAME_HEIGHT),
)
for frame in frames:
out.write(frame)
logging.info(f"Video for stream {camera_id} segment stored successfully.")
except Exception as e:
logging.error(
f"An error occurred while storing the video segment for stream {camera_id}: {e}"
)
finally:
if "out" in locals():
out.release()