# Cameras

> Use a phone or laptop, a camera link, a video file, or a camera on your home network through the bridge.

Page: https://percia.ai/docs/cameras. Index of all docs pages: https://percia.ai/docs/llms.txt

# Cameras

Pick the row that matches what you have.

| You have | Use | Source address |
|---|---|---|
| A spare phone, tablet or laptop | [Pair it by link or QR](#phone-tablet-or-computer) | `percia-cam://<id>` |
| A camera with a public RTSP or https address | [Camera link](#camera-link) | the link itself |
| A video file | [Upload](#video-files) | `percia-file://<id>` |
| A camera on your home or office network (ONVIF, RTSP, Frigate, Home Assistant, NVR) | [The bridge](#cameras-on-a-private-network) | `percia-cam://<id>` |

## Phone, tablet or computer

:::tabs
```bash curl
# 1. Create the camera. pairUrl is single use and valid for 10 minutes.
curl -sS -X POST "$BASE/cameras" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' -d '{"name":"Hall camera"}'
# {"camera":{...},"pairUrl":"https://.../cam/<token>","pairExpiresAt":"..."}

# 2. Open pairUrl on the device that will be the camera (copy the link or scan the QR code).
#    Allow the camera and press Start. The page shows "Percia is watching".

# 3. Wait until status is "online".
curl -sS "$BASE/cameras" -H "Authorization: Bearer $PERCIA_API_KEY"

# 4. Watch it.
curl -sS -X POST "$BASE/watches/owned" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' \
  -d '{"sourceUrl":"percia-cam://CAMERA_ID","goal":"A person is at the door"}'
```
```js JavaScript
const { camera, pairUrl } = await percia.cameras.create("Hall camera");
console.log("Open on the camera device:", pairUrl);
// later, once it is online:
await percia.watches.create({ sourceUrl: `percia-cam://${camera.id}`, goal: "A person is at the door" });
```
```python Python
res = client.cameras.create("Hall camera")
print("Open on the camera device:", res.pair_url)
```
```bash CLI
percia cameras add "Hall camera"     # prints the link and a QR code
percia watches create --source percia-cam://CAMERA_ID --goal "A person is at the door"
```
:::

- The device sends video only, no audio. Keep the screen on; on an iPhone the page must stay open.
- A camera is `online` while its last sign of life is under 60 seconds old, otherwise `offline` (or `never` if it never connected).
- A watch with no video for 60 minutes pauses itself and emails you. Resume it when the camera is back.
- A new pairing link (`POST /api/cameras/{id}/pair`) cancels an unused older one. Deleting a camera that has watches answers `409 camera_in_use`.
- Up to 50 cameras per account, camera links included (`429 camera_limit`).

## Camera link

A public `rtsp://`, `rtsps://`, `http://` or `https://` video address works as the `sourceUrl` directly. It must be reachable from the internet: Percia refuses `localhost`, `192.168.x.x`, `10.x.x.x`, `172.16-31.x.x`, `169.254.x.x` and names ending in `.local` or `.internal`.

If the address has a user name and password (`rtsp://user:pass@host/...`), Percia keeps them for judging only and removes them from every API answer and email.

## Video files

A video file is useful to try Percia without a camera. It plays once and the watch ends (`pausedReason: "file_done"`).

- **From a public https address:** `POST /api/uploads/from-url {"url":"https://example.com/clip.mp4"}`. Percia fetches the file itself (mp4, mov, webm or mkv, public https only) and answers `uploadId` and `source`.
- **From a person's device:** `POST /api/uploads/link` returns `uploadUrl`, a page valid for 30 minutes where the person picks the file. Then `GET /api/uploads` and take the newest file with `status: "ready"`.
- **In the app:** New watch, then Video file.

Use the upload's `source` (`percia-file://<uploadId>`) as the watch's `sourceUrl`. Both API routes need the `cameras:write` scope and answer 404 while video files are switched off for your host.

## Cameras on a private network

Percia never connects to a private address, and you should not open ports on your router. Instead the **Percia bridge** runs on an always-on computer in the same network as your cameras, reads each camera once, and pushes it to Percia over an outbound connection. The camera then appears in your Percia camera list and a watch uses `percia-cam://<id>`.

- Repository: [github.com/percia-ai/percia-bridge](https://github.com/percia-ai/percia-bridge)
- Docker image: `ghcr.io/percia-ai/percia-bridge`
- Finds ONVIF cameras, reads RTSP, Frigate and Home Assistant; there is a Home Assistant add-on.
- Needs an API key with the scopes `cameras:read`, `cameras:write` and `watches:delete`.

### Build your own connector

If you run an NVR or your own software, register a push camera and send video to it over WHIP:

```bash
curl -sS -X POST "$BASE/cameras" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' \
  -d '{"name":"Garage","kind":"push","externalId":"nvr-7-cam-3"}'
# 201 {"camera":{"id":"<uuid>","kind":"push",...},"whipUrl":"https://.../cam/<uuid>/whip","token":"pc_..."}
```

- `token` is shown once and can publish to this one camera only. Registering the same `externalId` again returns the same camera with `token: null`. `POST /api/cameras/{id}/token` makes a new token.
- Publish with ffmpeg 7.1 or newer (it needs the `whip` muxer), OBS 30 or newer (Service: WHIP, Server: the `whipUrl`, Bearer token: the token), or the CLI: `percia cameras push run --rtsp rtsp://user:pass@192.168.1.20/stream1`.
- Always use the `whipUrl` Percia returns, never one you remember: Percia may move a camera to another relay, so ask for the address again each time you start publishing (`GET /api/cameras/{id}/status`).
- `POST /api/cameras/bulk` registers up to 10 cameras at once.
- **Send a heartbeat about every 20 seconds**: `curl -fsS -X POST -H "Authorization: Bearer $PERCIA_CAMERA_TOKEN" "$BASE/cam/heartbeat"` (answers 204; no body). Without it a push camera shows offline about 60 seconds after it connects, even while it keeps publishing, and starting a [Live](https://percia.ai/docs/live.md) session on it answers `409 camera_offline`. `percia cameras push run` does this for you.

```bash
export PERCIA_CAMERA_TOKEN='pc_...'
ffmpeg -rtsp_transport tcp -i rtsp://USER:PASS@LAN-CAMERA/stream -an -c:v copy \
  -f whip -authorization "$PERCIA_CAMERA_TOKEN" "<whipUrl>"
```

The camera needs to send H.264 without B-frames. If it does not, re-encode it to H.264 baseline, 720p, 10 fps with no B-frames and no audio, for example `ffmpeg ... -an -vf "scale=-2:'min(ih,720)',fps=10,format=yuv420p" -c:v libx264 -profile:v baseline -tune zerolatency -bf 0 -g 20 -b:v 1500k`.
