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

# Recorded media

> Keep recordings, play them back, transcribe them through a transcription slot, and render them on your own compute.

> [!NOTE]
>
> These examples describe the current Bijection CLI and SDK source. Use builds
> from the same source commit for these APIs. The public CLI and npm SDK
> are published independently and may lag this reference.

The media library, `@bijectionhq/library-media`, keeps recorded media for
the app that places it: sources, recordings tiled by segments and gaps,
playback, retention and erasure, transcripts and renditions. `media({...})`
returns a subtree; its functions take their paths where you place it
(`cctv.recordings.open`).

```ts bijection/media.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, role, secret } from "@bijectionhq/bijection";
import { media, rendererReceiver } from "@bijectionhq/library-media";

export const site = label();
export const gateway = role({ clear: [site] });
export const operator = role({ clear: [site] });
export const renderUpload = secret();   // bijection secret set renderUpload

export const cctv = media({
  label: site,
  path: "/cctv",              // POST /cctv/segments, POST /cctv/renditions
  gateways: [gateway],        // camera relays and uploaders: ingest and register sources
  administrators: [operator], // sources, holds, erasure, transcripts, renditions
  retention: { days: 30 },
  transcriber: { engine: "aws-transcribe" }, // a transcription@1 slot at cctv.transcriber
  renderer: {
    receiver: rendererReceiver({ label: site }),
    upload: renderUpload,
  },
});
```

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app } from "@bijectionhq/bijection";
import { cctv, gateway, operator, renderUpload, site } from "./media";

export default app({ site, gateway, operator, renderUpload, cctv });
```

```ts bindings.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { placement } from "@bijectionhq/bijection";
import app from "./bijection/app";

const renderer = app.cctv.renderer;
if (!renderer) throw new Error("The media declaration needs a renderer");

export default placement.bindings([
  // cctv.transcriber is unbound: Bijection's managed Transcribe.
  placement.bind(renderer.launcher, placement.endpoint({
    url: "https://renderer.internal.example.com", credential: "cctv.renderer",
  })),
]);
```

Every fact is at `label`, and so are segment files, utterances and
rendition files: everything derived from a recording carries its label.
The transcriber and renderer are [slots](https://docs.bijection.com/operate/placement.md) placed inside
the subtree (`cctv.transcriber`, `cctv.renderer.launcher`).

* The transcriber is a `transcription@1` slot needing the engine you name.
  Unbound, it is Bijection's managed Transcribe on the cell's AWS account
  (`aws-transcribe`, priced per second with a 15-second minimum). A
  successful answer requires deletion of the staged segment, output and
  job. The host gives a send at most ten seconds for processing and cleanup.
  A managed send registers independent cleanup before staging. If the send
  reaches its deadline, the outcome can be unknown while cleanup waits for
  the job to finish and deletes its job record and late output. The cleanup
  workflow runs for up to seven days. The staging bucket expires objects
  after one day, and AWS can retain an undeleted job record for up to 90 days.
  `placement.managed({ account: placement.aws.account({ account, region,
  staging }) })` runs the same engine and driver on your AWS account. Use a staging
  bucket with no versioning history, with `s3:GetBucketVersioning` granted
  to the role. Configure expiration for staged objects in your account and
  remove terminal jobs that outlive the host's deadline.
  `placement.endpoint(...)` reaches any server that speaks the protocol,
  such as the compute pack's `bijection_compute.speech` with a Whisper
  engine.
* The renderer is a worker pool slot (`worker@1`). No host offers it today,
  so the bindings file binds it to your launcher with `placement.endpoint`,
  `workerPool.aws` or `workerPool.gcp`; unbound, it is refused at deploy
  with `PlacementUnavailable` (`NotOffered`). The launcher is sent the
  bearer its binding's `credential` names (`bijection secret set
  cctv.renderer`), unless the receiver is given `auth`.

Functions refuse with `Invalid`, `Absent`, `Conflict`, `Erased`,
`Disallowed` or the codes in `MEDIA_REFUSES`. Absent arguments are `null`;
lists take `{ size, cursor }` and answer `{ facts, next }`.

## Record

A gateway opens a recording on a source, posts each segment's bytes to
`POST <path>/segments` (session-verified, at most 8 MiB of fragmented MP4)
and appends it by sequence, interval, size and SHA-256 with
`recordings.appendSegment`. The segment route admits only ingesters, and a
staged segment is kept only once its uploader's append names it. Segments
(at most 30 seconds) and gaps tile the recording. `recordings.seal` with
`final: true` ends the source's timeline.

Pass source positions such as `{ microseconds: 1_000_000n }` as
`sourceFrom` when opening a recording and as `from` and `to` when appending
a segment or recording a gap. Each position is a signed 64-bit integer in
whole microseconds on the recording's timeline. An interval includes
`from` and excludes `to`. The open result's `end` is the next append
position.

## Play back

`playback.page` lists segments and gaps over a `from` and `to` interval.
Continue a truncated page at its `nextFrom`. Use `playback.bytes` to open a
segment's file under the reader's clearance.
For browser playback UI, install the `recordings` kit elements from
`ui.bijection.com` (`@bijection/recording-player`, `@bijection/frame-strip`,
`@bijection/observation-timeline`).

## Retain and erase

A segment expires `retention` after it is appended (the source's
retention, else the subtree's). Its expiry turn deletes it, the host
retires its file, and an `expired` gap takes its place, unless a hold
keeps the recording. `recordings.hold` and `recordings.unhold`, or
`cctv.hold(ctx, …)` and `cctv.unhold(ctx, key)` in your own function, keep
the library's retention ledger. `recordings.erase` deletes a sealed,
unheld recording and everything derived from it in bounded rounds.

## Transcribe and render

* `transcripts.request` (or `cctv.transcribe(ctx, …)`) submits one
  `transcribe` task per segment to the transcriber, its File sent by
  reference, at most eight at a time. Reviewers
  correct utterances at the revision they saw (`transcripts.correct`);
  `transcripts.captions` pages WebVTT and `transcripts.lookup` finds text.
* `renditions.request` (or `cctv.render(ctx, …)`) submits one run to the
  renderer with a recipe: thumbnail, poster, waveform, page image, tile,
  PDF slice, annotation, DICOM frame, spreadsheet or email JSON. OCR is a
  [document reader](https://docs.bijection.com/models/extraction.md#the-document-reader), not a
  rendition.
  The renderer posts its output to `POST <path>/renditions`
  (bearer-verified with `renderer.upload`), and the continuation attaches
  the upload whose SHA-256 matches.

The renderer's Python side and the transcription reference provider ship in
`@bijectionhq/pack-compute`'s Python package (`bijection_compute.media`,
`bijection_compute.speech`).


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