How do I stop video streaming and rediect to another webpage in flask

I am trying to build a web application using flask, in which I stream a video using webcam and save it, and then redirect to another html page. However, when streaming stops, the screen freezes to the last frame. Please let me know what I am doing wrong and how do I resolve it.

import cv2
import os
import numpy as np
from flask import Flask,request,render_template, redirect,url_for,Response
import imutils


@app.route("/",methods=["POST", "GET"])
def index():
    return render_template('login.html')

def gen_frames():
    camera = cv2.VideoCapture(0)
    while count!=100:
        success, frame =  # read the camera frame
        if not success:
            ret, buffer = cv2.imencode('.jpg', frame)
            frame = buffer.tobytes()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')  # concat frame one by one and show result
        if count==99:
            return render_template('success.html')


@app.route("/sign_in",methods=["POST", "GET"])
def sign_in():
    return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__=="__main__":

Read more here:

Content Attribution

This content was originally published by rossgeller13 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: