Stream compressed video from python backend to react frontend

,

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.

StackOverflow will be your best bet to get answer for such a question.
P.S.: I do not work at StackOverflow.

Honestly, I think what you are doing is the best way to do it. If you are not looking to scale to large number of users, having users upload to S3, then having S3 kick off a notification to your server to copy the video and then process it. I don’t think cloudfront or Kinesis is going to gain you anything.

Great. I’m concerned about streaming this video back as it is being processed. You think sending each frame via post response is the best way?

Great. I just posted there.