1#!/usr/bin/env python
2from flask import Flask, render_template, Response
3from camera import Camera
4
5app = Flask(__name__)
6
7@app.route('/')
8def index():
9 return render_template('index.html')
10
11def gen(camera):
12 while True:
13 frame = camera.get_frame()
14 yield (b'--frame\r\n'
15 b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
16
17@app.route('/video_feed')
18def video_feed():
19 return Response(gen(Camera()),
20 mimetype='multipart/x-mixed-replace; boundary=frame')
21
22if __name__ == '__main__':
23 app.run(host='0.0.0.0', debug=True)
1<html>
2 <head>
3 <title>Video Streaming Demonstration</title>
4 </head>
5 <body>
6 <h1>Video Streaming Demonstration</h1>
7 <img src="{{ url_for('video_feed') }}">
8 </body>
9</html>