# ๐Ÿค– Web AI Agent - Video Integration Guide This guide provides the essential information for integrating USDA Vision Camera video streaming into your web application. ## ๐ŸŽฏ Quick Start ### Video Streaming Status: โœ… READY - **Progressive streaming implemented** - Videos play in browsers (no download) - **86 MP4 files available** - All properly indexed and streamable - **HTTP range requests supported** - Seeking and progressive playback work - **Memory efficient** - 8KB chunked delivery ## ๐Ÿš€ API Endpoints ### Base URL ``` http://localhost:8000 ``` ### 1. List Available Videos ```http GET /videos/?camera_name={camera}&limit={limit} ``` **Example:** ```bash curl "http://localhost:8000/videos/?camera_name=camera1&limit=10" ``` **Response:** ```json { "videos": [ { "file_id": "camera1_auto_blower_separator_20250805_123329.mp4", "camera_name": "camera1", "file_size_bytes": 1072014489, "format": "mp4", "status": "completed", "is_streamable": true, "created_at": "2025-08-05T12:43:12.631210" } ], "total_count": 1 } ``` ### 2. Stream Video (Progressive) ```http GET /videos/{file_id}/stream ``` **Example:** ```bash curl "http://localhost:8000/videos/camera1_auto_blower_separator_20250805_123329.mp4/stream" ``` **Features:** - โœ… Progressive streaming (8KB chunks) - โœ… HTTP range requests (206 Partial Content) - โœ… Browser compatible (HTML5 video) - โœ… Seeking support - โœ… No authentication required ### 3. Get Video Thumbnail ```http GET /videos/{file_id}/thumbnail?timestamp={seconds}&width={px}&height={px} ``` **Example:** ```bash curl "http://localhost:8000/videos/camera1_auto_blower_separator_20250805_123329.mp4/thumbnail?timestamp=5.0&width=320&height=240" ``` ## ๐ŸŒ Web Integration ### HTML5 Video Player ```html ``` ### React Component ```jsx function VideoPlayer({ fileId, width = "100%" }) { const streamUrl = `http://localhost:8000/videos/${fileId}/stream`; const thumbnailUrl = `http://localhost:8000/videos/${fileId}/thumbnail`; return ( ); } ``` ### Video List Component ```jsx function VideoList({ cameraName = null, limit = 20 }) { const [videos, setVideos] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const params = new URLSearchParams(); if (cameraName) params.append('camera_name', cameraName); params.append('limit', limit.toString()); fetch(`http://localhost:8000/videos/?${params}`) .then(response => response.json()) .then(data => { // Filter only streamable MP4 videos const streamableVideos = data.videos.filter( v => v.format === 'mp4' && v.is_streamable ); setVideos(streamableVideos); setLoading(false); }) .catch(error => { console.error('Error loading videos:', error); setLoading(false); }); }, [cameraName, limit]); if (loading) return
Loading videos...
; return (
{videos.map(video => (

{video.file_id}

Camera: {video.camera_name}

Size: {(video.file_size_bytes / 1024 / 1024).toFixed(1)} MB

))}
); } ``` ## ๐Ÿ“Š Available Data ### Current Video Inventory - **Total Videos**: 161 files - **MP4 Files**: 86 (all streamable โœ…) - **AVI Files**: 75 (legacy format, not prioritized) - **Cameras**: camera1, camera2 - **Date Range**: July 29 - August 5, 2025 ### Video File Naming Convention ``` {camera}_{trigger}_{machine}_{YYYYMMDD}_{HHMMSS}.mp4 ``` **Examples:** - `camera1_auto_blower_separator_20250805_123329.mp4` - `camera2_auto_vibratory_conveyor_20250805_123042.mp4` - `20250804_161305_manual_camera1_2025-08-04T20-13-09-634Z.mp4` ### Machine Triggers - `auto_blower_separator` - Automatic recording triggered by blower separator - `auto_vibratory_conveyor` - Automatic recording triggered by vibratory conveyor - `manual` - Manual recording initiated by user ## ๐Ÿ”ง Technical Details ### Streaming Implementation - **Method**: FastAPI `StreamingResponse` with async generators - **Chunk Size**: 8KB for optimal performance - **Range Requests**: Full HTTP/1.1 range request support - **Status Codes**: 200 (full), 206 (partial), 404 (not found) - **CORS**: Enabled for all origins - **Caching**: Server-side byte-range caching ### Browser Compatibility - โœ… Chrome/Chromium - โœ… Firefox - โœ… Safari - โœ… Edge - โœ… Mobile browsers ### Performance Characteristics - **Memory Usage**: Low (8KB chunks, no large file loading) - **Seeking**: Instant (HTTP range requests) - **Startup Time**: Fast (metadata preload) - **Bandwidth**: Adaptive (only downloads viewed portions) ## ๐Ÿ› ๏ธ Error Handling ### Common Scenarios ```javascript // Check if video is streamable const checkVideo = async (fileId) => { try { const response = await fetch(`http://localhost:8000/videos/${fileId}`); const video = await response.json(); if (!video.is_streamable) { console.warn(`Video ${fileId} is not streamable`); return false; } return true; } catch (error) { console.error(`Error checking video ${fileId}:`, error); return false; } }; // Handle video loading errors const VideoPlayerWithErrorHandling = ({ fileId }) => { const [error, setError] = useState(null); const handleError = (e) => { console.error('Video playback error:', e); setError('Failed to load video. Please try again.'); }; if (error) { return
โŒ {error}
; } return (