Import
Functions
| Function | Description |
|---|---|
start_stream() | Start a webcam stream |
stop_stream() | Stop a webcam stream |
get_stream_info() | Get info about an active stream |
get_active_streams() | List all active stream names |
rename_stream() | Rename an active stream |
WebcamService.get_stream_url() | Get just the URL for a stream |
Function Reference
start_stream(net_name, video_device, dut_ip)
Start a webcam video stream.
| Parameter | Type | Description |
|---|---|---|
net_name | str | Unique name for this stream |
video_device | str | Video device path (e.g., /dev/video0) |
dut_ip | str | Lager Box IP address for URL generation |
dict with keys:
url- Full stream URL (e.g.,http://100.91.127.26:8081/)port- Port number for the streamalready_running- Boolean indicating if stream was already active
RuntimeError if device is already in use or not found
stop_stream(net_name)
Stop an active webcam stream.
| Parameter | Type | Description |
|---|---|---|
net_name | str | Name of the stream to stop |
bool - True if stopped successfully, False if not running
get_stream_info(net_name, dut_ip)
Get information about an active stream.
| Parameter | Type | Description |
|---|---|---|
net_name | str | Name of the stream |
dut_ip | str | Lager Box IP address |
dict or None - Stream info dict or None if not running
get_active_streams()
Get a list of all active stream names.
list[str] - List of active stream names
rename_stream(old_name, new_name)
Rename an active stream.
| Parameter | Type | Description |
|---|---|---|
old_name | str | Current stream name |
new_name | str | New stream name |
bool - True if renamed, False if stream not found
WebcamService Class
For more control, use theWebcamService class directly.
WebcamService()
Create a webcam service instance.
start_stream(net_name, video_device, dut_ip)
Start a stream (same as module function).
stop_stream(net_name)
Stop a stream (same as module function).
get_stream_url(net_name, dut_ip)
Get just the URL for a stream.
cleanup_dead_streams()
Remove state for streams whose processes have died.
Stream State Management
The webcam service manages stream state in/etc/lager/webcam_streams.json.
WebcamStreamState
Internal class for state management.
Stream Features
Zoom Control
Streams support digital zoom from 1.0x to 4.0x:POST /api/zoom/in- Increase zoom by 0.25xPOST /api/zoom/out- Decrease zoom by 0.25xPOST /api/zoom/reset- Reset to 1.0xGET /api/zoom- Get current zoom level
FPS Monitoring
The stream reports real-time FPS:GET /api/fps- Get current FPS
Examples
Start Multiple Cameras
Stream Management Script
Visual Inspection Test
Camera Discovery
Web Interface
Each stream provides a web interface at its URL with:- Live MJPEG video stream
- Zoom controls (+, -, Reset)
- FPS display
- Sidebar with links to other active streams
API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/ | GET | HTML page with video viewer |
/stream | GET | Raw MJPEG video stream |
/api/zoom | GET | Get current zoom level |
/api/zoom/in | POST | Increase zoom |
/api/zoom/out | POST | Decrease zoom |
/api/zoom/reset | POST | Reset zoom to 1.0x |
/api/fps | GET | Get current FPS |
/api/streams | GET | List all active streams |
/test | GET | Health check endpoint |
Hardware Requirements
| Requirement | Description |
|---|---|
| USB Webcams | UVC-compatible cameras |
| Video Devices | /dev/video* device files |
| OpenCV | Required for video capture |
Notes
- Streams run on ports starting from 8081
- Each stream uses a separate port, automatically allocated
- Streams persist until explicitly stopped or the process dies
- Dead stream processes are automatically cleaned up
- Only one stream can use a video device at a time
- Default resolution is 640x480 at 30 FPS
- JPEG quality is set to 80 for bandwidth/quality balance
- Streams are accessible via HTTP from any network the Lager Box is on
- Zoom is digital (crop and scale), not optical

