> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lagerdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webcam

> Manage webcam streams on boxes

Control webcam streaming for visual monitoring of devices.

## Syntax

```bash theme={null}
lager webcam [NETNAME] COMMAND [OPTIONS]
```

## Commands

| Command | Description |
| - | - |
| `start` | Start webcam stream |
| `snapshot` | Save one JPEG frame from a running stream |
| `stop` | Stop webcam stream |
| `url` | Print URLs of all active streams |
| `start-all` | Start all webcam streams |
| `stop-all` | Stop all webcam streams |

## Options

| Option | Description |
| - | - |
| `--box BOX` | Lager Box name or IP address |

***

## Command Reference

### `start`

Start a webcam stream.

```bash theme={null}
lager webcam CAM1 start --box my-lager-box
```

Add `--open` to also open the stream in your web browser:

```bash theme={null}
lager webcam CAM1 start --open --box my-lager-box
```

If the stream runs already, `start` changes nothing on the box. It
prints the link again, so `start --open` also reopens the viewer with a fresh
link. If the browser does not open, open the printed link yourself.

### `snapshot`

Save one frame from a running stream as a JPEG. This is the right way for
scripts and assistants to look at the bench. The frame comes back over the
box's command endpoint, so the stream's own port never has to be reachable.

```bash theme={null}
lager webcam CAM1 snapshot --box my-lager-box --out frame.jpg
```

Without `--out` the file is named `CAM1-<timestamp>.jpg` in the current
directory. An existing file at the `--out` path is overwritten. On success the
command prints `Saved frame.jpg (<N> bytes)`.

The stream must already be running. If it is not, the command exits `1` with
`Error: Hardware error: No active stream for net 'CAM1' — start it first`.

The first snapshot after `start` can take up to 5 seconds, because the camera
opens on the first request. If no frame arrives in that time, the error ends in
`streamer answered 503`. A box older than 0.47.0 answers
`Error: Unknown action 'snapshot' for webcam`. Run `lager update` on that box.

### `stop`

Stop a webcam stream.

```bash theme={null}
lager webcam CAM1 stop --box my-lager-box
```

### `url`

Print URLs of all active webcam streams, with who started each one when
the box recorded it.

```bash theme={null}
lager webcam url --box my-lager-box
```

Output:

```
Active webcam streams on <BOX_IP>:

CAM1:
  Port: 8086
  Device: /dev/video0
  Origin: started via cli by alice
  http://<BOX_IP>:8086/
```

Each link is on a line of its own, so you can copy it with a triple-click.

### Access-gated boxes

When a box sits behind an access gateway, its stream ports only admit
requests that carry your sign-in token. A browser cannot attach one from a
plain link. So `start`, `start-all` and `url` append the token to the
printed URL (`http://<BOX_IP>:8086/?token=...`), and print a note under it:

```
Webcam URL:
http://<BOX_IP>:8086/?token=...
Open this link within 15 minutes; it carries your sign-in.
If it has expired, or the viewer later asks for sign-in, run: lager webcam url --box my-lager-box

To stop the stream: lager webcam CAM1 stop --box my-lager-box
```

The token only has to be valid when you open the link. The gateway then
gives the browser a session of its own, and the gateway decides how long
that session lasts. A current gateway keeps it for up to 24 hours, or until
your access to the box is removed. An older gateway ends it when the token
expires. Before it prints a link, the CLI checks your sign-in. If less than
half of the token's lifetime is left, the CLI renews it. A new link can then
usually be opened for about 15 minutes. If the link no longer opens, or an
open viewer asks you to sign in, run `lager webcam url` for a new link.

With `LAGER_GATEWAY_TOKEN` set, the link carries that token instead, and
can be opened while that token is valid. If no sign-in is stored for the
box, the CLI tells you which `lager login` URL to use.

### `start-all`

Start all configured webcam streams.

```bash theme={null}
lager webcam start-all --box my-lager-box
```

### `stop-all`

Stop all webcam streams.

```bash theme={null}
lager webcam stop-all --box my-lager-box
```

***

## Usage

### Basic Workflow

```bash theme={null}
# Start a webcam
lager webcam CAM1 start --box my-lager-box

# Or start it and open it in a browser in one step
lager webcam CAM1 start --open --box my-lager-box

# Get the stream URL
lager webcam url --box my-lager-box

# Stop when done
lager webcam CAM1 stop --box my-lager-box
```

### Multiple Cameras

```bash theme={null}
# Start all cameras
lager webcam start-all --box my-lager-box

# View all URLs
lager webcam url --box my-lager-box

# Stop all cameras
lager webcam stop-all --box my-lager-box
```

***

## Stream Format

Webcam streams are provided as:

* **HTTP MJPEG streams** for browser viewing (`/stream`)
* **Single JPEG frames** on demand (`/snapshot`, or `lager webcam NET snapshot`)
* **Per-webcam ports** (8086, 8087, etc.)
* **Device path reporting** for debugging

Streams can be started and stopped from the CLI, the Python API, or other
tools that manage the same box. Each stream records which surface started
it, and any of them can stop it. One stream serves every viewer at once, but
a video device can only belong to one stream. Stop a stream before starting
another on the same camera.

Starting a stream changes no camera setting. Focus, exposure, white balance and
the other image controls keep the camera's values until you change one. Change
them on the viewer page or from the [Python API](https://docs.lagerdata.com/source/reference/python/webcam.md#camera-controls).
What you change is kept for the net and put back each time its stream starts.
The Python API page lists the cameras `lager nets add-all` detects.

***

## Use Cases

### Visual Inspection

Monitor physical state of device during testing:

```bash theme={null}
lager webcam BENCH_CAM start
# Run tests while monitoring
lager webcam BENCH_CAM stop
```

### Remote Debugging

View LED states, display outputs, or physical connections:

```bash theme={null}
lager webcam url --box my-lager-box
# Open stream in browser
```

### Documentation

Capture visual evidence of test results:

```bash theme={null}
lager webcam BOARD_VIEW start
lager webcam BOARD_VIEW snapshot --out after-flash.jpg
lager webcam BOARD_VIEW stop
```

***

## Examples

```bash theme={null}
# Set default webcam
lager defaults add --webcam-net MAIN_CAM

# Quick start/stop
lager webcam start
lager webcam stop

# Check status
lager webcam url
```

***

## Notes

* Webcams must be connected via USB to the box
* Each webcam uses a unique port (8086+)
* Streams are reachable at the box IP address. On an access-gated box, a link
  works only with the sign-in token that the CLI adds to it
* Default net can be set with `lager defaults add --webcam-net`
* USB webcams must be compatible with V4L2


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.