|
2 | 2 | from datetime import datetime |
3 | 3 |
|
4 | 4 | import cv2 |
5 | | -import numpy as np |
| 5 | +import tempfile |
6 | 6 | from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__ |
7 | 7 |
|
8 | 8 |
|
@@ -33,30 +33,23 @@ def create_azure_container(container_name = "alerts"): |
33 | 33 | def upload_blob(videoArray, videoName, width, height, fps): |
34 | 34 |
|
35 | 35 | 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" |
40 | 40 | blob_client = blob_service_client.get_blob_client(container="alerts", blob=videoName) |
41 | 41 |
|
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() |
44 | 47 |
|
| 48 | + with open(temp_video_file.name, "rb") as data: |
| 49 | + # Uploading video to the cloud |
| 50 | + blob_client.upload_blob(data) |
45 | 51 |
|
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 |
60 | 53 |
|
61 | 54 | return blob_client.url |
62 | 55 |
|
|
0 commit comments