-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from teapot2/storage
Storage
- Loading branch information
Showing
3 changed files
with
122 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
FRAME_WIDTH = 720 | ||
FRAME_HEIGHT = 480 | ||
FRAME_SIZE_BYTES = FRAME_HEIGHT * FRAME_WIDTH * 3 | ||
|
||
VIDEO_SEGMENTATION_INTERVAL = 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import config | ||
import time | ||
import cv2 | ||
import os | ||
|
||
fourcc = cv2.VideoWriter_fourcc("m", "p", "4", "v") | ||
|
||
|
||
# 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: | ||
frame: The frame data to be stored. | ||
Returns: | ||
None | ||
Stores the segmented and compressed video data to the specified storage location or file system. | ||
""" | ||
try: | ||
storage_path = f"C:/Users/Sebastián/Documents/Tec/SF/multiprocessing_test/storage/{camera_id}/" | ||
current_date = time.strftime("%Y-%m-%d") | ||
current_time = time.strftime("%H-%M-%S") | ||
filename = f"video_{current_date}_{current_time}.mp4" | ||
|
||
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) | ||
|
||
print(f"Video for stream {camera_id} segment stored successfully: {storage_path + filename}") | ||
|
||
except Exception as e: | ||
print(f"An error occurred while storing the video segment: {e}") | ||
|
||
finally: | ||
out.release() |