# Encode on a PC you own

Connect a computer with a GPU, at home or in an office, as an encoder for your ClipMux server.

Source: https://clipmux.com/docs/self-host/encoding/your-pc

A PC agent is a computer you own that encodes for your ClipMux server, with
its GPU if it has one. It connects out to the server, so it works behind
NAT, and it holds no storage credentials: each job gives it a token and
signed URLs for that job alone. It suits a small server with a GPU
elsewhere, or a library of videos already on one machine.

This is a command-line option. The dashboard doesn't list PCs: you pair,
route and revoke them with `clipmux` commands and the
[management API](/docs/reference/management-api). Most installs don't need
one, because the server's own encoder already uses its GPU, and a VPS can
use [Modal](/docs/self-host/encoding/modal) or
[RunPod](/docs/self-host/encoding/runpod).

## Before you start [#before-you-start]

- On Linux: amd64 or arm64 with glibc 2.39 or newer, such as Ubuntu 24.04,
  Debian 13 or Fedora 40 and later. Elsewhere (Windows, macOS, or another
  Linux), Docker.
- The server's public URL, for example `https://video.example.com`,
  reachable from the PC. With videos stored on the server's disk, the PC
  downloads sources and uploads output through it.
- A shell on the ClipMux server, to make a pairing code.

## Install the agent on Linux [#install-the-agent-on-linux]

<Steps>
<Step>
### Make a pairing code [#make-a-pairing-code]

On the server:

```bash
cd /opt/clipmux && sudo docker compose exec app clipmux admin create-pairing --app studio-pc
```

`--app` names the PC (the default is its hostname). The code is already
approved, works once, and expires after 15 minutes. `POST /v1/agents/pairings`
makes one through the API.
</Step>

<Step>
### Run the installer on the PC [#run-the-installer-on-the-pc]

```bash
curl -fsSL https://clipmux.com/install-agent.sh | sudo sh -s -- \
  --server https://video.example.com --pair ABCD-EFGH
```

The installer downloads the agent for the PC's architecture, checks it
against the release's `SHA256SUMS`, and sets up a systemd service that
starts it at boot. The agent comes with its own FFmpeg, Shaka Packager and
VAAPI drivers, so nothing else needs installing.

- **With `sudo`**, it installs to `/opt/clipmux-agent`, with a system
  service that runs as a `clipmux-agent` user in the `video` and `render`
  groups, for the GPU.
- **Without `sudo`**, it installs to `~/.local/share/clipmux-agent`, with a
  user service, and asks systemd to keep it running while you're logged out.

On a machine without systemd, it prints the command to run the agent
yourself.
</Step>
</Steps>

| Option | What it does |
| --- | --- |
| `--server URL` | The ClipMux server's public URL. |
| `--pair CODE` | The pairing code. Not needed to upgrade. |
| `--name NAME` | What to call this PC. The default is its hostname. |
| `--version vX.Y.Z` | Install that release instead of the latest. |
| `--uninstall` | Stop and remove the agent. Its connection is kept for a reinstall. |
| `--purge` | With `--uninstall`, also forget the connection. |

Run the installer again to upgrade; the connection is kept.

## Or connect from the PC itself [#or-connect-from-the-pc-itself]

If `clipmux` is already on the PC, start it with the server's URL:

```bash
clipmux worker --server https://video.example.com
```

It prints a code and opens the server's **Connect a PC** page
(`/workers/connect`) in your browser. Check the code matches, and choose
**Connect**. On a machine without a browser, open the printed link anywhere
you're signed in to the dashboard. The agent keeps its key in `agent.json`
(mode 0600) in your config directory, so from then on `clipmux worker` alone
starts it.

## Run the agent in Docker [#run-the-agent-in-docker]

On Windows, macOS, or a Linux without glibc 2.39, the ClipMux image is also
the agent:

```bash
docker run -d --name clipmux-agent --restart unless-stopped --no-healthcheck \
  --user "$(id -u):$(id -g)" \
  -v "$HOME/.config/clipmux:/var/lib/clipmux-agent" -e CLIPMUX_AGENT_DIR=/var/lib/clipmux-agent \
  ghcr.io/visheshgubrani/clipmux:v1.0.0 worker --server https://video.example.com --pair ABCD-EFGH
```

The image tag is your server's own release, so the agent speaks its worker
API. It runs as your user and keeps its connection in `~/.config/clipmux`, where
a restarted container finds it again. For a GPU, add one of these after
`docker run`:

- **NVIDIA** (Linux, or Windows through WSL2 and Docker Desktop):
  `--gpus all`. This needs the NVIDIA Container Toolkit.
- **AMD or Intel** (Linux):
  `--device /dev/dri --group-add "$(getent group render | cut -d: -f3)"`.

Docker Desktop on a Mac runs Linux in a VM without the GPU, so it encodes on
the CPU. The sandbox still holds there.

## Send jobs to PCs [#send-jobs-to-pcs]

A fresh install sends jobs to this server and paired PCs alike, so a PC
starts taking jobs as soon as it connects. Choosing **This server** or a
cloud GPU on **Encoding** changes that: PCs then take only the jobs of
videos they registered themselves (below).

To send jobs to PCs again, set routing through the API, signed in as the
owner (the routes need the dashboard's session cookie):

```bash
curl -X PUT https://video.example.com/v1/settings/routing \
  -H 'Content-Type: application/json' \
  --cookie "__Host-clipmux_session=…" \
  -d '{"primary_executor": "workers"}'
```

`workers` is this server and PCs; `agents` is PCs only. See
[Routing, fallback and spend limits](/docs/self-host/encoding/routing-and-limits).

## Encoders [#encoders]

The agent tests each GPU path when it starts and offers only the ones that
pass: `nvenc`, `vaapi`, `cuda-decode`, then `cpu`, with the hybrid paths for
sources the GPU can't decode. It's the same choice as on the server; see
[Encode on this server](/docs/self-host/encoding/this-server). `--encoder`
(or `CLIPMUX_ENCODER`) picks the first path to try, `CLIPMUX_VAAPI_DEVICE`
picks a render node, and `--encoder cpu` skips the GPU.

The Linux agent has no CUDA build of whisper.cpp, so on an NVIDIA card it
transcribes with Vulkan.

## Videos that stay on the PC [#videos-that-stay-on-the-pc]

```bash
clipmux push --local ~/Videos/course
```

The files aren't uploaded. The agent on this PC registers them, encodes them
where they are, and uploads only the encrypted output. Without an API key
they become your own uploads, as if from the dashboard; with
`CLIPMUX_API_KEY` set, the key's app owns them.

- Jobs for these videos run only on this PC. While it's asleep they wait,
  and they fail as `agent_unavailable` if it stays away for 7 days.
- A file that changes or disappears before it's encoded fails its job as
  `source_changed` or `source_missing`, and the video keeps playing what it
  had.
- `--upload-source` also uploads each file to the server's storage after
  encoding it here, so any encoder can re-encode it later.
- To limit which folders `push --local` may hand over, list them in
  `agent.json`: `{ "roots": ["/home/me/Videos"] }`.
- In Docker, mount the videos at the same path inside the container, for
  example `-v "$HOME/Videos:$HOME/Videos:ro"`.

<Note>
These videos' sources never leave the PC unless you pass
`--upload-source`. Back them up yourself: if the PC's disk dies, the
videos keep playing, but can't be re-encoded.
</Note>

## The sandbox [#the-sandbox]

Every ffmpeg and packager run on the PC is confined: no network, writes
only to the job's own directory, reads only system paths and the job's
source, with CPU, memory and file limits. An agent where the sandbox can't
hold (not Linux, or an old kernel) refuses to start unless you pass
`--unsandboxed`. It then takes only jobs pinned to it and the files you
upload in the dashboard, never an app's uploads or a file imported from a
URL.

## Check it works [#check-it-works]

```bash
clipmux worker doctor
```

It checks the connection, the server, the key, the tool versions, the
sandbox, each encoder and scratch disk space, marking each with ✓ or ✗. Fix
the first ✗. `clipmux worker doctor --offline` skips the first three, to
check a machine before it's connected. With the system service, run it as
the service's user:
`sudo -u clipmux-agent /usr/local/bin/clipmux worker doctor`.

- **`key accepted` ✗**: the server revoked this PC. Remove `agent.json` and
  pair again.
- **`scratch disk`**: a source needs about three times its size free.
- **The installer says the agent didn't connect**: the code expired or was
  used. Make a new one.

`GET /v1/agents` lists the PCs the server knows, with whether each is online
and sandboxed. The service's log is in `journalctl -u clipmux-agent` (or
`journalctl --user -u clipmux-agent` for a user install).

## Disconnect a PC [#disconnect-a-pc]

`DELETE /v1/agents/{id}` revokes the PC at once: its key stops working, and
a job it was running moves to another encoder without using up a retry. If
you no longer trust what it encoded, `POST /v1/agents/{id}/reencode`
re-encodes every video whose current version that PC made. The dashboard
lists no PCs, so revoke one you no longer use: it keeps its key until you
do. Then run the installer with `--uninstall --purge` on the PC.

## Next [#next]

- [Routing, fallback and spend limits](/docs/self-host/encoding/routing-and-limits)
- [Encode on this server](/docs/self-host/encoding/this-server)
- [Command line](/docs/reference/cli)
