Docker_APP / app.py
Raumkommander's picture
Create app.py
43384f2 verified
raw
history blame
754 Bytes
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
import cv2
app = FastAPI()
# Open webcam (or use a video file)
video_source = 0 # Change to "video.mp4" for a file
cap = cv2.VideoCapture(video_source)
def generate_frames():
while True:
success, frame = cap.read()
if not success:
break
_, buffer = cv2.imencode(".jpg", frame)
yield (b"--frame\r\n"
b"Content-Type: image/jpeg\r\n\r\n" +
buffer.tobytes() + b"\r\n")
@app.get("/video")
async def video_feed():
return StreamingResponse(generate_frames(), media_type="multipart/x-mixed-replace; boundary=frame")
@app.get("/")
def index():
return {"message": "Video Streaming with FastAPI"}