Implement RTSP streaming functionality for cameras
- Added endpoints to start and stop RTSP streaming for cameras in the API. - Enhanced CameraManager and CameraStreamer classes to manage RTSP streaming state and processes. - Updated API documentation to include new RTSP streaming commands. - Modified Docker configurations to include FFmpeg for RTSP streaming support. - Adjusted MediaMTX settings for improved stream handling and timeout configurations.
This commit is contained in:
@@ -7,6 +7,7 @@ This module provides REST API endpoints and WebSocket support for dashboard inte
|
||||
import asyncio
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
from typing import Dict, List, Optional, Any
|
||||
from datetime import datetime, timedelta
|
||||
import threading
|
||||
@@ -347,6 +348,45 @@ class APIServer:
|
||||
self.logger.error(f"Error stopping camera stream: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@self.app.post("/cameras/{camera_name}/start-rtsp")
|
||||
async def start_camera_rtsp_stream(camera_name: str):
|
||||
"""Start RTSP streaming for a camera to MediaMTX"""
|
||||
try:
|
||||
if not self.camera_manager:
|
||||
raise HTTPException(status_code=503, detail="Camera manager not available")
|
||||
|
||||
success = self.camera_manager.start_camera_rtsp_streaming(camera_name)
|
||||
if success:
|
||||
rtsp_url = f"rtsp://{os.getenv('MEDIAMTX_HOST', 'localhost')}:{os.getenv('MEDIAMTX_RTSP_PORT', '8554')}/{camera_name}"
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Started RTSP streaming for camera {camera_name}",
|
||||
"rtsp_url": rtsp_url
|
||||
}
|
||||
else:
|
||||
return {"success": False, "message": f"Failed to start RTSP streaming for camera {camera_name}"}
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error starting RTSP stream: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@self.app.post("/cameras/{camera_name}/stop-rtsp")
|
||||
async def stop_camera_rtsp_stream(camera_name: str):
|
||||
"""Stop RTSP streaming for a camera"""
|
||||
try:
|
||||
if not self.camera_manager:
|
||||
raise HTTPException(status_code=503, detail="Camera manager not available")
|
||||
|
||||
success = self.camera_manager.stop_camera_rtsp_streaming(camera_name)
|
||||
if success:
|
||||
return {"success": True, "message": f"Stopped RTSP streaming for camera {camera_name}"}
|
||||
else:
|
||||
return {"success": False, "message": f"Failed to stop RTSP streaming for camera {camera_name}"}
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error stopping RTSP stream: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@self.app.get("/cameras/{camera_name}/config", response_model=CameraConfigResponse)
|
||||
async def get_camera_config(camera_name: str):
|
||||
"""Get camera configuration"""
|
||||
|
||||
Reference in New Issue
Block a user