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=Flask(__name__)

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

def gen_frames():
    count=1
    camera = cv2.VideoCapture(0)
    while count!=100:
        success, frame = camera.read()  # read the camera frame
        if not success:
            break
        else:
            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')
            break

        count+=1

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


if __name__=="__main__":
   app.run()


Read more here: https://stackoverflow.com/questions/66384689/how-do-i-stop-video-streaming-and-rediect-to-another-webpage-in-flask

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: