Comments (2)
Sounds good, for future searchers, this mostly works...
#!/usr/bin/env python
from importlib import import_module
import os
from flask import Flask, render_template, Response
# import camera driver
# Valid values for Camera Library are:
# pi for Picamera
# pi2 for Picamera2
# opencv for opencv
if os.environ.get("CAMERA"):
Camera = import_module("camera_" + os.environ["CAMERA"]).Camera
else:
# Camera Emulator with 1.jpg, 2.jpg, 3.jpg
from camera import Camera
app = Flask(__name__)
@app.route("/")
def index():
"""Video streaming home page."""
return render_template("index.html")
def gen(camera):
"""Video streaming generator function."""
yield b"--frame\r\n"
while True:
frame = camera.get_frame()
yield b"Content-Type: image/jpeg\r\n\r\n" + frame + b"\r\n--frame\r\n"
@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"
)
@app.route("/thumbnail")
def get_thumbnail():
""" After the camera stops, this no longer works.
"""
frame = Camera().get_frame()
return Response(frame, mimetype="image/jpeg")
if __name__ == "__main__":
app.run(host="0.0.0.0", threaded=True)
It moves the loading of the correct libraries to the else and adds a thumbnail route.
It does seem to have some sort of timing issue when adding the MJPEG config in Home Assistant. Sometimes the thumbnail doesn't validate. If I figure out a better solution, I'll post another comment on this closed issue. I think I fixed that.
from flask-video-streaming.
I don't see this as part of this project. The idea of this repository is to demonstrate how to implement the video streaming aspect, and the intention is for this code to be a companion to my blog articles on this topic. Adding other features would make more sense on a dedicated project, which you may want to based off of this code, if you like.
from flask-video-streaming.
Related Issues (20)
- How to send meta data Along with the image stream ? HOT 3
- The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a generator. HOT 3
- How does darknet yolo call the USB camera? HOT 1
- I need this to run in SSL HOT 1
- How to control the speed of video feed flow showing in the webpage? HOT 2
- Can we sync Flask streaming response with OpenCV FPS HOT 5
- IOError: [Errno 104] Connection reset by peer HOT 5
- Allways save the video as mp4 file? HOT 3
- I want to send a string alongwith each frame. HOT 4
- Loading the video stream freezes up all other responses from the Flask server HOT 4
- resetting yield generator during long run HOT 5
- Frames Are Displayed With Delay of One Frame
- Gstreamer backend
- Rotated Pictures HOT 1
- Hello, I don't know why the front-end console can receive a bunch of late results only after the back-end program is finished
- Publish the video through MotionEye HOT 6
- Picamera2/libcamera compatibility HOT 1
- Concurrency question HOT 3
- Stopping/Restarting video stream? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-video-streaming.