Browse Source

re-introduce video-feed

main
Hendrik Langer 4 years ago
parent
commit
a0230e344d
  1. 15
      raspberry/roberto/__init__.py
  2. 2
      raspberry/roberto/camera/base_camera.py
  3. 34
      raspberry/roberto/views/frontend/routes.py

15
raspberry/roberto/__init__.py

@ -7,17 +7,26 @@ from flask_socketio import SocketIO
#######################
#### Configuration ####
#https://www.patricksoftwareblog.com/structuring-a-flask-project/
#######################
platform = None
try:
import RPi.GPIO as gpio
platform = 'raspberry'
except (ImportError, RuntimeError):
platform = 'generic'
# Create the instances of the Flask extensions (flask-sqlalchemy, flask-login, etc.) in
# the global scope, but without any arguments passed in. These instances are not attached
# to the application at this point.
login = LoginManager()
login.login_view = "users.login"
socketio = SocketIO()
#from roberto.camera.camera_opencv import Camera
#camera = Camera()
if platform == 'raspberry':
from roberto.camera.camera_pi import Camera
else:
from roberto.camera.camera_opencv import Camera
camera = Camera()
from roberto.camera.camera_gstreamer_webrtc import WebRTCCamera
webrtccamera = WebRTCCamera()
from roberto.Serial import Serial

2
raspberry/roberto/camera/base_camera.py

@ -97,7 +97,7 @@ class BaseCamera(object):
# if there hasn't been any clients asking for frames in
# the last 10 seconds then stop the thread
if time.time() - BaseCamera.last_access > 10:
if time.time() - BaseCamera.last_access > 3:
frames_iterator.close()
print('Stopping camera thread due to inactivity.')
break

34
raspberry/roberto/views/frontend/routes.py

@ -11,23 +11,23 @@ from flask import Response
def index():
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')
#
#
#@frontend_blueprint.route('/video_feed')
#def video_feed():
# """Video streaming route. Put this in the src attribute of an img tag."""
# from roberto import camera
# camera.__init__()
# response = Response(gen(camera),
# mimetype='multipart/x-mixed-replace; boundary=frame')
# response.headers.add('X-Accel-Buffering', 'no')
# return response
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')
@frontend_blueprint.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
from roberto import camera
camera.__init__()
response = Response(gen(camera),
mimetype='multipart/x-mixed-replace; boundary=frame')
response.headers.add('X-Accel-Buffering', 'no')
return response
@frontend_blueprint.route('/gamepad.js')

Loading…
Cancel
Save