how to read cv2 output stream

Viewed 24

I am working a project where I am reading input stream from an ip camera using cv2.videocapture(input_rstp), for the output stream the code is as follows

def open_output_stream(address, fps, frame_size):
    output_stream = None
    if address != '':
        if not address.endswith('.avi'):
            pass #Write warning
    
        output_stream = cv2.VideoWriter(address, cv2.VideoWriter.fourcc(*'MJPG'), fps, frame_size)

    return output_stream

now videowriter function is for writing files and this function is not saving the file to the temp folder and the route for web app is picking up file from this and displaying on the webapp:

@app.route('/static/temp/video/<filename>')
def get_video_file(filename):
    filename = os.path.join(CONFIG['TEMP']['temp_processing_path'], filename)
    return send_file(filename)

so I was thinking I could create and send the file as binary object(blob) rather than file itself so I can display this on different displays(client) using sockets or rtsp, so I was thinking of using socket but the issue that wasn't working for external ip's due firewall restrictions. if that could work I could use:

frame = buffer.tobytes()
yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

Kindly help me with this!

0 Answers
Related