<filename>main/streaming_app/__init__.py
"""------------------------------------------------------------*-
  Init module for Flask server
  Tested on: Raspberry Pi 3 B+
  (c) <NAME> 2020
  (c) <NAME> 2018
  version 1.00 - 11/04/2020
 --------------------------------------------------------------
 * Server created for the purpose of streaming video
 * Make the server a fully functional package
 *
 * ref:
 * - https://blog.miguelgrinberg.com/post/video-streaming-with-flask
 * - https://blog.miguelgrinberg.com/post/flask-video-streaming-revisited
 * - https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database
 
 --------------------------------------------------------------"""
from importlib import import_module
from flask import Flask, render_template, Response
from streaming_app.config import Config
from streaming_app.camera_pi import Camera # Raspberry Pi camera module (requires picamera package)

stream_app = Flask(__name__)
stream_app.config.from_object(Config)

# @stream_app.route('/')
# def index():
#     """Video streaming home page."""
#     return render_template('index.html')


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


@stream_app.route('/video_feed')
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

<filename>main/streaming_app/__init__.py
"""------------------------------------------------------------*-
  Init module for Flask server
  Tested on: Raspberry Pi 3 B+
  (c) <NAME> 2020
  (c) <NAME> 2018
  version 1.00 - 11/04/2020
 --------------------------------------------------------------
 * Server created for the purpose of streaming video
 * Make the server a fully functional package
 *
 * ref:
 * - https://blog.miguelgrinberg.com/post/video-streaming-with-flask
 * - https://blog.miguelgrinberg.com/post/flask-video-streaming-revisited
 * - https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database
 
 --------------------------------------------------------------"""
from importlib import import_module
from flask import Flask, render_template, Response
from streaming_app.config import Config
from streaming_app.camera_pi import Camera # Raspberry Pi camera module (requires picamera package)

stream_app = Flask(__name__)
stream_app.config.from_object(Config)

# @stream_app.route('/')
# def index():
#     """Video streaming home page."""
#     return render_template('index.html')


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


@stream_app.route('/video_feed')
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

------------------------------------------------------------*-   Init module for Flask server   Tested on: Raspberry Pi 3 B+   (c) <NAME> 2020   (c) <NAME> 2018   version 1.00 - 11/04/2020  --------------------------------------------------------------  * Server created for the purpose of streaming video  * Make the server a fully functional package  *  * ref:  * - https://blog.miguelgrinberg.com/post/video-streaming-with-flask  * - https://blog.miguelgrinberg.com/post/flask-video-streaming-revisited  * - https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database    -------------------------------------------------------------- # Raspberry Pi camera module (requires picamera package) # @stream_app.route('/') # def index(): #     """Video streaming home page.""" #     return render_template('index.html') Video streaming generator function. Video streaming route. Put this in the src attribute of an img tag.