I’m quite new to AWS. I’m building an app, where the user uploads a video into s3, I copy the video to ec2, open the video with OpenCV, process it frame by frame via my algorithm. As it happens, I want to stream the processed frames to the react frontend and show it as a live video.
i.e., the stripped-down version of the python code that runs in ec2 is:
import cv2
'''copy from s3'''
path = "file.mp4"
''' stripped down version of actual algorithm'''
while True:
cap = cv2.VideoCapture(path)
while cap.isOpened(): # loop over frames
ret, frame = cap.read()
if ret: # valid frame
''' algorithm modifies the frame here'''
''' stream these frames to frontend in a compressed way'''
print(frame.shape) # (480,704,3)
Question: What is the best way to stream back the processed video from here to react frontend?
The super dumb way to do it will be to just convert the numpy array into bytes and send it back via a POST response. That would result in 33 GB/h. The next dumb way would be to compress each frame as jpg (320 MB/h) or webp (160 MB/h) and send it via POST response.
Note: Resolution/quality isn’t the issue in my case. I can stream at the lowest quality at the lowest size. The purpose is just to show the user the algorithm is working on their video.
Someone mentioned Kinesis and I came across Cloudfront, but I am unable to understand how they can solve this problem.
PS: I got downvoted the last time I posted here. If this group is not for beginners, kindly let me know where else I can post this and get help.