I am able to collect frames from RTSP camera using the below code. But need help with storing the data in S3 buckets as a video file. But storing frames takes up lot of storage space.
How do platforms like youtube store the streaming data? How to stream data in VP9, VP8 or H.264 data but store it on AWS in .mov format?
Need to reduce network usage and storage usage.
def __init__(self, src=0):
# Set camera config object to 'src' variable
# Create CV2 stream object
self.camera = src['rtsp_link']
self.capture = cv.VideoCapture(self.camera)
# Queue created
self.q = queue.Queue(maxsize=1)
# Camera id that maps to sqlite table name
self.cam_id = src['cam_id']
# Lower Frames per second reduces network usage and CPU/Memory
self.resize = (int(self.capture.get(3)/src['resize_factor']),
int(self.capture.get(4)/src['resize_factor']))
# Start the thread to read frames from the video stream
self.thread = Thread(target=self.update, args=())
self.thread.daemon = True
self.thread.start()
self.msgBody = {}
print("Program initialized")
self.debug_flag = 0
def update(self):
# Read the next frame from the stream in a different thread
while True:
if self.capture.isOpened():
(self.status, self.frame) = self.capture.read()
while not self.status:
print("Video Stream could not read at: {}".format(time.time()))
self.capture.release()
time.sleep(5)
try:
self.capture = cv.VideoCapture(self.camera)
if self.capture.isOpened():
print("Video stream reconnected")
(self.status, self.frame) = self.capture.read()
except:
print("Unable to reconnect to camera stream. Alert!")
pass
if not self.q.empty():
try:
# Discard previous (unprocessed) frame
self.q.get_nowait()
except queue.Empty:
print("No frames in queue.")
pass
self.q.put(self.frame)
if self.debug_flag:
print("Queue updated.")
wondering if this would help
cv2.VideoWriter_fourcc(‘H’,’2′,’6′,’4′)