steam-server/app/routes/stream.py

18 lines
535 B
Python
Raw Normal View History

2024-12-12 20:04:36 +08:00
from fastapi import APIRouter
from app.services.stream_manager import stop_stream
from app.services.ffmpeg_service import stream_rtsp_to_flv
2024-12-13 18:21:25 +08:00
from app.utils.result import Result
2024-12-12 20:04:36 +08:00
router = APIRouter()
@router.get("/get_stream")
2024-12-13 18:21:25 +08:00
async def get_stream(camera_id: str):
flv_url = await stream_rtsp_to_flv(camera_id)
if flv_url is None:
return Result.error("0001", "Stream not started")
return Result.ok(flv_url)
2024-12-12 20:04:36 +08:00
@router.get("/stop_stream")
def stop(id: str):
stop_stream(id)
return {"message": "Stream stopped"}