This demo shows how the Moondream VLM can analyze live video feeds in real time, trigger alerts for specific behaviors, and present the results in a lightweight web UI built with React and Vite.
- 🎥 Real-time webcam/video analysis - Stream from your camera or upload a video
- 💬 Live visual summaries - Continuous narration with custom prompts
- 🎯 Gesture detection - Pre-defined triggers (smiling, thumbs up, peace sign, etc.)
- ⚡ Custom triggers - Create your own action detectors
- 🖥️ Fullscreen support - Immersive viewing experience
- 💾 Persistent storage - Custom triggers saved in browser
-
Install dependencies
pnpm install
-
Add your Moondream API key to
.env,.env.local, or.env.developmentin the project root:MOONDREAM_API_KEY=sk-your-moondream-key
You can generate keys from your Moondream dashboard. Keep this file out of version control.
-
Start the Vite dev server
pnpm dev
The app runs at http://localhost:5173 by default. Allow camera access in the browser when prompted.
-
(Optional) Test the production build
pnpm build && pnpm preview
- Point the
Playercomponent’sinferenceUrlprop at a proxy or self-hosted Moondream deployment if you don’t want to callhttps://api.moondream.ai/v1directly. - Need to test across devices? Run
pnpm dev --hostso phones on your LAN can reach the dev server.
src/App.tsxmounts thePlayerand injects the Moondream endpoint. This keeps the demo single-purpose and easy to embed elsewhere.- Player Orchestration (
src/components/solutions/analyze-live-video/player.tsx) wires together three domain-specific hooks:useVideoSessionmanages the video element, fullscreen state, media permissions, and frame capture (built on top ofsrc/hooks/useLiveVideo.ts).useTriggerManagerowns predefined + custom triggers, persists user-defined triggers tolocalStorage, and exposes the active Moondream queries/notification copy.useAnalysisSessionbridges the video session withuseFrameAnalysisso captured frames run through Moondream and results are stored in a rolling history.
- Frame Analysis Pipeline (
src/hooks/useFrameAnalysis.ts) debounces frame grabs, calls the Moondream/queryendpoint with both the free-form summary prompt and the trigger prompt, retries on throttling, and emits structured results/notifications. - Presentation Layer (
src/components/solutions/analyze-live-video/player-surface.tsxand overlays) renders the actual video canvas plus:StartOverlayfor webcam/file selection.PromptControlsOverlayfor the free-form prompt + trigger picker (built with headless UI primitives).ResultOverlayfor the scrolling stack of answers/notifications so users can see what Moondream detected.CustomTriggerDialogfor composing new trigger rules without touching code.
- Utility Hooks (
src/hooks/useLiveVideo.ts) encapsulate raw MediaStream handling, auto-mirroring for front cameras, video file ingestion, inactivity timeouts, and frame-to-canvas capture, keeping React components declarative.
Together these layers show how to: (1) capture live video, (2) query Moondream with flexible prompts, and (3) surface detections in a polished UI that end-users can tweak without redeploying code.