我可以使用以下代码从 RTSP 相机收集帧。但需要帮助将数据作为视频文件存储在 S3 存储桶中。但是存储框架会占用大量存储空间。
youtube 等平台如何存储流媒体数据?如何以 VP9、VP8 或 H.264 数据流式传输数据,但以 .mov 格式将其存储在 AWS 上?
需要减少网络使用和存储使用。
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.")
想知道这是否有帮助
cv2.VideoWriter_fourcc(‘H’,’2′,’6′,’4′)