Adding initial camera functions
This commit is contained in:
37
src/app.py
37
src/app.py
@@ -1,6 +1,10 @@
|
||||
from collections.abc import Generator
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from flask import Flask, Response, jsonify
|
||||
from flask import Flask, Response, jsonify, render_template
|
||||
|
||||
from src.camera import camera
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -18,5 +22,34 @@ def heartbeat() -> tuple[Response, int]:
|
||||
)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def index() -> str:
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@app.post("/camera/start")
|
||||
def camera_start() -> tuple[Response, int]:
|
||||
camera.start()
|
||||
return jsonify({"status": "started"}), 200
|
||||
|
||||
|
||||
@app.post("/camera/stop")
|
||||
def camera_stop() -> tuple[Response, int]:
|
||||
camera.stop()
|
||||
return jsonify({"status": "stopped"}), 200
|
||||
|
||||
|
||||
@app.get("/camera/stream")
|
||||
def camera_stream() -> Response:
|
||||
def generate() -> Generator[bytes, Any, Any]:
|
||||
for frame in camera.frames():
|
||||
yield (b"--frame\r\n" b"Content-Type: video/H264\r\n\r\n" + frame + b"\r\n")
|
||||
|
||||
return Response(
|
||||
generate(),
|
||||
mimetype="multipart/x-mixed-replace; boundary=frame",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
||||
|
||||
Reference in New Issue
Block a user