Skip to content

Commit eced453

Browse files
committed
Review- Updating upload_blob function
1 parent 4075fc5 commit eced453

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

cloudStorage.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import datetime
33

44
import cv2
5-
import numpy as np
5+
import tempfile
66
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
77

88

@@ -33,30 +33,23 @@ def create_azure_container(container_name = "alerts"):
3333
def upload_blob(videoArray, videoName, width, height, fps):
3434

3535
blob_service_client = init_blob_client()
36-
current_time = datetime.now()
37-
current_day = datetime.today()
38-
current_time = current_time.strftime("%H:%M:%S")
39-
videoName = videoName + " " + str(current_day) + " "+ current_time + ".mp4"
36+
current_time = datetime.now().strftime("%H:%M:%S")
37+
current_day = datetime.today().strftime("%Y-%m-%d")
38+
39+
videoName = f"{videoName} {current_day} {current_time}.mp4"
4040
blob_client = blob_service_client.get_blob_client(container="alerts", blob=videoName)
4141

42-
# Converting videoArray ( numpy array ) into video
43-
# fps = 30 # 25 frames per second
42+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_video_file:
43+
output = cv2.VideoWriter(temp_video_file.name, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height), True)
44+
for i in videoArray:
45+
output.write(i)
46+
output.release()
4447

48+
with open(temp_video_file.name, "rb") as data:
49+
# Uploading video to the cloud
50+
blob_client.upload_blob(data)
4551

46-
# print(videoName)
47-
output = cv2.VideoWriter(videoName, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height), True)
48-
for i in videoArray:
49-
output.write(i)
50-
output.release()
51-
52-
path = "./" + videoName
53-
# print("path : ", path)
54-
with open(path, "rb") as data :
55-
# Uploading video to the cloud
56-
blob_client.upload_blob(data)
57-
# Delete file after upload
58-
59-
os.remove(path)
52+
os.remove(temp_video_file.name) # removing temporary file after upload
6053

6154
return blob_client.url
6255

0 commit comments

Comments
 (0)