我有一个python应用程序,需要在浏览器中显示视频流。为了显示流,我向另一个路由(/video\u feed)发出请求。代码如下:
@app.route("/video_feed")
def video_feed():
# return the response generated along with the specific media
# type (mime type)
return Response(generate(),
mimetype="multipart/x-mixed-replace; boundary=frame")
def generate():
# grab global references to the output frame and lock variables
global outputFrame, lock
# loop over frames from the output stream
while True:
# wait until the lock is acquired
with lock:
# check if the output frame is available, otherwise skip
# the iteration of the loop
if outputFrame is None:
continue
# encode the frame in JPEG format
(flag, encodedImage) = cv2.imencode(".jpg", outputFrame)
# ensure the frame was successfully encoded
if not flag:
continue
# yield the output frame in the byte format
yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' +
bytearray(encodedImage) + b'\r\n')
<html>
<head>
<title>Pi Video Surveillance</title>
</head>
<body>
<h1>Pi Video Surveillance</h1>
<img src="{{ url_for('video_feed') }}">
</body>
</html>
@app.route('/stream')
def show_video_stream():
return render_template("stream.html")
def prepare_video_stream():
print("It might be streaing")
global outputFrame, lock
coordinates_file = "data/parking_spot_coordinates.yml"
with open(coordinates_file, "r") as coordinates_data:
coordinates = yaml.load(coordinates_data)
stream_url = os.environ.get('RTSP_URL')
video_stream = VideoStream(coordinates)
# video_stream.stream_video()
video_capture = cv2.VideoCapture(stream_url)
fps = video_capture.get(cv2.CAP_PROP_FPS)
print(fps)
video_capture.set(cv2.CAP_PROP_BUFFERSIZE, 0)
while video_capture.isOpened():
frame = video_stream.get_frame(video_capture)
# acquire the lock, set the output frame, and release the
# lock
with lock:
outputFrame = frame.copy()
@app.before_first_request
def start_stream_processing_thread():
# # start a thread that will perform motion detection
t = threading.Thread(target=prepare_video_stream)
t.daemon = True
t.start()
当使用内置flask服务器在本地运行时,一切都正常,但我尝试将应用程序部署到heroku,并使用gunicorn作为服务器。以下是程序文件:
web: gunicorn app:app
检查heroku日志时,我得到以下信息: 错误R14(超出内存配额)
我怎样才能避免这种情况
目前没有回答
相关问题 更多 >
编程相关推荐