通过flask完成web实时播放视频

def gen():
    r = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, password=PASS_WORD)
    while True:
        try:
            # print(r.get('pic_path').decode())
            img = cv2.imread(r.get('realtime_frame').decode(), 1)
            # img = cv2.imread("static/result.png", 1)
            ret, jpeg = cv2.imencode('.jpg', img)
            frame = jpeg.tobytes()
            # frame = {'file': open(r.get('pic_path'), 'rb')}
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
        except:
            pass


@bp.route('/video_feed')
def video_feed():
    return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')
posted @ 2023-02-17 11:04  bitterteaer  阅读(275)  评论(0编辑  收藏  举报