samedi 27 juin 2015

video streaming using flask with raspi-camera

Sorry for my English skill. I want to make a web page which streams video and runs several functions. I am using python and flask server. But, there are some problems which I can't solve alone. I have a source code. It's almost perfect.

source code.

import time
from flask import Flask, render_template, Response
from camera import Camera

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

def gen(camera):
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

@app.route('/video_feed')
def video_feed():
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

@app.route('/test')
def test():
    return time.time() 

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True

and template

<html>
  <head>
    <title>Video Streaming Demonstration</title>
  </head>
  <body>
    <h1>Video Streaming Demonstration</h1>
    <img src="{{ url_for('video_feed') }}">
  </body>
</html>

In the source code, the function named gen() is using 'yield'. so, It will never end. It take all resource. I want to run another function like 'test' function while video is streaming.

Aucun commentaire:

Enregistrer un commentaire