How to receive a webcam video stream in flask route? How to receive a webcam video stream in flask route? flask flask

How to receive a webcam video stream in flask route?


You should probably use stream_with_context around your stream generator to stream your response. You can't return a regular response because there is anything that tells the client not to close the connection.

https://flask.palletsprojects.com/en/1.1.x/api/#flask.stream_with_context


Hey this might help you video streaming in flask

#!/usr/bin/env pythonfrom flask import Flask, render_template, Responsefrom camera import Cameraapp = Flask(__name__)@app.route('/')def index():return render_template('index.html')def gen(camera):while True:    frame = camera.get_frame()    yield (b'--frame\r\n'           b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')    @app.route('/video_feed')    def video_feed():    return Response(gen(Camera()),                mimetype='multipart/x-mixed-replace; boundary=frame')    if __name__ == '__main__':    app.run(host='0.0.0.0', debug=True)