Skip to content

Commit 909d069

Browse files
committed
add flask-22-opencv-rtsp-streaming
1 parent ac99e74 commit 909d069

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from flask import Flask, render_template, Response
2+
import cv2
3+
4+
app = Flask(__name__)
5+
6+
# camera = cv2.VideoCapture('rtsp://admin:admin@172.21.182.12:554/cam/realmonitor?channel=1&subtype=1')
7+
camera = cv2.VideoCapture(0)
8+
9+
10+
def gen_frames():
11+
while True:
12+
success, frame = camera.read()
13+
if not success:
14+
break
15+
else:
16+
ret, buffer = cv2.imencode('.jpg', frame)
17+
frame = buffer.tobytes()
18+
yield (b'--frame\r\n'
19+
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
20+
21+
22+
@app.route('/video_feed')
23+
def video_feed():
24+
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
25+
26+
27+
@app.route('/')
28+
def index():
29+
return render_template('index.html')
30+
31+
32+
if __name__ == '__main__':
33+
app.run(host='0.0.0.0', debug=True)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
7+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
8+
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
9+
10+
<title>Live Streaming</title>
11+
</head>
12+
<body>
13+
<div class="container">
14+
<div class="row">
15+
<div class="col-lg-8 offset-lg-2">
16+
<h3 class="mt-5">Live Streaming</h3>
17+
<img src="{{ url_for('video_feed') }}" width="100%">
18+
</div>
19+
</div>
20+
</div>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)