# ๐ฌ Video Streaming Module The USDA Vision Camera System now includes a modular video streaming system that provides YouTube-like video playback capabilities for your React web application. ## ๐ Features - **HTTP Range Request Support** - Enables seeking and progressive download - **Native MP4 Support** - Direct streaming of MP4 files with automatic AVI conversion - **Intelligent Caching** - Optimized streaming performance - **Thumbnail Generation** - Extract preview images from videos - **Modular Architecture** - Clean separation of concerns ## ๐๏ธ Architecture The video module follows clean architecture principles: ``` usda_vision_system/video/ โโโ domain/ # Business logic (pure Python) โโโ infrastructure/ # External dependencies (OpenCV, FFmpeg) โโโ application/ # Use cases and orchestration โโโ presentation/ # HTTP controllers and API routes โโโ integration.py # Dependency injection and composition ``` ## ๐ API Endpoints ### List Videos ```http GET /videos/ ``` **Query Parameters:** - `camera_name` - Filter by camera - `start_date` - Filter by date range - `end_date` - Filter by date range - `limit` - Maximum results (default: 50) - `include_metadata` - Include video metadata **Response:** ```json { "videos": [ { "file_id": "camera1_recording_20250804_143022.mp4", "camera_name": "camera1", "filename": "camera1_recording_20250804_143022.mp4", "file_size_bytes": 31457280, "format": "mp4", "status": "completed", "created_at": "2025-08-04T14:30:22", "is_streamable": true, "needs_conversion": true } ], "total_count": 1 } ``` ### Stream Video ```http GET /videos/{file_id}/stream ``` **Headers:** - `Range: bytes=0-1023` - Request specific byte range **Features:** - Supports HTTP range requests for seeking - Returns 206 Partial Content for range requests - Automatic format conversion for web compatibility - Intelligent caching for performance ### Get Video Info ```http GET /videos/{file_id} ``` **Response includes metadata:** ```json { "file_id": "camera1_recording_20250804_143022.avi", "metadata": { "duration_seconds": 120.5, "width": 1920, "height": 1080, "fps": 30.0, "codec": "XVID", "aspect_ratio": 1.777 } } ``` ### Get Thumbnail ```http GET /videos/{file_id}/thumbnail?timestamp=5.0&width=320&height=240 ``` Returns JPEG thumbnail image. ### Streaming Info ```http GET /videos/{file_id}/info ``` Returns technical streaming details: ```json { "file_id": "camera1_recording_20250804_143022.avi", "file_size_bytes": 52428800, "content_type": "video/x-msvideo", "supports_range_requests": true, "chunk_size_bytes": 262144 } ``` ## ๐ React Integration ### Basic Video Player ```jsx function VideoPlayer({ fileId }) { return ( ); } ``` ### Advanced Player with Thumbnail ```jsx function VideoPlayerWithThumbnail({ fileId }) { const [thumbnail, setThumbnail] = useState(null); useEffect(() => { fetch(`${API_BASE_URL}/videos/${fileId}/thumbnail`) .then(response => response.blob()) .then(blob => setThumbnail(URL.createObjectURL(blob))); }, [fileId]); return ( ); } ``` ### Video List Component ```jsx function VideoList({ cameraName }) { const [videos, setVideos] = useState([]); useEffect(() => { const params = new URLSearchParams(); if (cameraName) params.append('camera_name', cameraName); params.append('include_metadata', 'true'); fetch(`${API_BASE_URL}/videos/?${params}`) .then(response => response.json()) .then(data => setVideos(data.videos)); }, [cameraName]); return (