What You’ll Build
A React application that:- Captures webcam video using the browser’s MediaStream API
- Connects to Decart’s real-time API for video transformation
- Displays input and transformed video side-by-side
- Allows dynamic prompt updates without reconnecting
- Manages connection state and error handling
Prerequisites
- Node.js 18 or higher
- A Decart API key
- A webcam for testing
Setup
Start the development server
Main Application Component
TheApp.tsx component manages the prompt state and renders the video stream:
VideoStream Component
TheVideoStream component handles the real-time connection and video display:
Key Concepts
Model Configuration
The example usesmirage_v2 for real-time style transformation:
fps, width, and height that should be used when requesting the webcam stream.
Camera Access
Request camera access with constraints matching the model’s requirements:Real-time Connection
Connect to the real-time API with the input stream and configuration:Dynamic Prompt Updates
Update the style prompt without reconnecting:enhance option uses AI to improve prompt quality for better results.
Event Handling
Subscribe to connection state changes and errors:Cleanup
Always disconnect when the component unmounts:Available Models
You can use different real-time models:mirage_v2- MirageLSD video restyling (recommended)mirage- Original MirageLSD modellucy_v2v_720p_rt- Lucy for video editing (add/change objects)lucy_2_rt- Lucy 2 with reference image support