# Frame recording types

## PibblFrameRecordingOptions

`PibblFrameRecordingOptions` requires `duration` in milliseconds and accepts
`frameRate`, `memoryHeadroom`, and an optional cancellation `signal`. The optional
`onRenderComplete` callback observes each root render after render-owned state has
published. It receives a `committed` event with a committed `generation` or a
`failed` event for an attempted generation. Failed attempts never yield pixel
frames; a failed capture rejects. `onFrameCaptured` observes the exact generation
after its RGBA bytes are copied, which can occur later than the render-completion
callback when capture coalesces renders.

## PibblRenderCompletion

`PibblRenderCompletion` distinguishes committed generations from failed attempts.
Only committed generations can identify recorded pixel evidence.

## PibblFrameRecordingSession

`PibblFrameRecordingSession` exposes `ready`, `finished`, `stop()`, and `cancel()`.
Stop preserves captured frames. Cancel discards an active session.

## PibblFrameRecording

`PibblFrameRecording` exposes actual `duration`, immutable `frames` metadata,
`readFrame(index)`, and idempotent `dispose()`. Each read returns a caller-owned
copy; disposal releases worker-owned pixels and cancels pending operations.

## PibblRecordedFrameInfo

`PibblRecordedFrameInfo` contains `renderGeneration`, the committed root render
generation whose pixels were copied; `timestamp` in milliseconds from capture
start; and physical backing `width` and `height`. Timestamps measure wall-clock
capture time, can coalesce multiple renders, and are not generation identifiers.

## PibblRecordedFrame

`PibblRecordedFrame` adds `data`, a
`Uint8ClampedArray` of RGBA8 bytes.

## PibblGifExportOptions

`PibblGifExportOptions` accepts `frameRate` (default 25, maximum 100), `repeatCount`
(omitted plays once, zero loops forever, positive values repeat), an opaque CSS
`background`, an abort `signal`, and `onProgress(progress)` from zero to one.

Export quality and size controls:

- `width` and `height`: integer output dimensions from 1 to 65535. One dimension
  preserves aspect ratio; both specify the exact size. Omitted dimensions keep
  the original bitmap size. Resizing uses premultiplied-alpha bilinear sampling.
- `maxColors`: integer 2–256, default 256. Includes the transparency entry when
  `background` is omitted. GIF color tables round up to a power of two.
- `palette`: optional array of opaque CSS colors, used exactly instead of an
  automatically selected palette. Its length must fit `maxColors`, allowing one
  extra entry for transparent export. Unrepresented pixels use the nearest RGB
  palette color. Partial-alpha colors are rejected.
- `dithering`: boolean, default false. Enables Floyd–Steinberg error diffusion.
- `quantizationSampleFactor`: integer 1–30, default 10. One spends most NeuQuant
  training effort; larger factors sample less and run faster.
- `paletteSampleCount`: integer 1–16777216, default 262144. Caps pixels sampled
  across up to 32 representative output frames for palette selection.

A supplied palette bypasses both automatic sampling controls. All exports keep
recorded pixels unchanged, so a recording can be exported repeatedly with different
settings. GIF compression itself is lossless over the resulting palette indexes;
color reduction, binary transparency, resizing and frame sampling may lose detail.

See [recordFrames and exportGif](/reference/functions/record-frames/).

## API details from source

<span id="api-PibblFrameRecordingOptions"></span>

### PibblFrameRecordingOptions

Options for capturing committed renders of one live Pibbl root.

```ts
interface PibblFrameRecordingOptions
```

Related API: [PibblFrameRecordingOptions](/reference/types/frame-recording/#pibblframerecordingoptions).

#### See also

[PibblFrameRecordingSession](/reference/types/frame-recording/#pibblframerecordingsession)

[View source — packages/core/src/lib/recording/types.ts:4](/source/packages/core/src/lib/recording/types-ts/#L4)

#### Properties and methods

<span id="api-PibblFrameRecordingOptions-duration"></span>
<details>
<summary>duration</summary>


```ts
duration: number
```

Recording length in milliseconds, measured after initialization.

[View source — packages/core/src/lib/recording/types.ts:6](/source/packages/core/src/lib/recording/types-ts/#L6)

</details>

<span id="api-PibblFrameRecordingOptions-frameRate"></span>
<details>
<summary>frameRate (optional)</summary>


```ts
frameRate?: number | undefined
```

Maximum capture frequency; defaults to 60 frames per second.

[View source — packages/core/src/lib/recording/types.ts:8](/source/packages/core/src/lib/recording/types-ts/#L8)

</details>

<span id="api-PibblFrameRecordingOptions-memoryHeadroom"></span>
<details>
<summary>memoryHeadroom (optional)</summary>


```ts
memoryHeadroom?: number | undefined
```

Initial estimated memory multiplier; defaults to 1.15. Memory may grow.

[View source — packages/core/src/lib/recording/types.ts:10](/source/packages/core/src/lib/recording/types-ts/#L10)

</details>

<span id="api-PibblFrameRecordingOptions-signal"></span>
<details>
<summary>signal (optional)</summary>


```ts
signal?: AbortSignal | undefined
```

Related API: [signal](/reference/functions/signal/).

Aborting discards the recording, including during initialization.

[View source — packages/core/src/lib/recording/types.ts:12](/source/packages/core/src/lib/recording/types-ts/#L12)

</details>

<span id="api-PibblFrameRecordingOptions-onRenderComplete"></span>
<details>
<summary>onRenderComplete (optional)</summary>


```ts
onRenderComplete?: ((completion: PibblRenderCompletion) => void) | undefined
```

Related API: [PibblRenderCompletion](/reference/types/frame-recording/#pibblrendercompletion).

Observe each root render after its committed application state is published.
Failed attempts are reported separately and never produce recorded frames.

##### Parameters

- **`completion`** — The committed or failed root render attempt.

[View source — packages/core/src/lib/recording/types.ts:18](/source/packages/core/src/lib/recording/types-ts/#L18)

</details>

<span id="api-PibblFrameRecordingOptions-onFrameCaptured"></span>
<details>
<summary>onFrameCaptured (optional)</summary>


```ts
onFrameCaptured?: ((frame: PibblRecordedFrameInfo) => void) | undefined
```

Related API: [PibblRecordedFrameInfo](/reference/types/frame-recording/#pibblrecordedframeinfo).

Observe the exact committed generation after its RGBA pixels were copied.

##### Parameters

- **`frame`** — Metadata identifying the captured root bitmap.

[View source — packages/core/src/lib/recording/types.ts:22](/source/packages/core/src/lib/recording/types-ts/#L22)

</details>

<span id="api-PibblFrameRecordingSession"></span>

### PibblFrameRecordingSession

An active capture; stop keeps frames and cancel discards them.

```ts
interface PibblFrameRecordingSession
```

Related API: [PibblFrameRecordingSession](/reference/types/frame-recording/#pibblframerecordingsession).

#### See also

[PibblFrameRecording](/reference/types/frame-recording/#pibblframerecording)

[View source — packages/core/src/lib/recording/types.ts:46](/source/packages/core/src/lib/recording/types-ts/#L46)

#### Properties and methods

<span id="api-PibblFrameRecordingSession-ready"></span>
<details>
<summary>ready</summary>


```ts
readonly ready: Promise<void>
```

Resolves after frame zero has been captured and capture has started.

[View source — packages/core/src/lib/recording/types.ts:48](/source/packages/core/src/lib/recording/types-ts/#L48)

</details>

<span id="api-PibblFrameRecordingSession-finished"></span>
<details>
<summary>finished</summary>


```ts
readonly finished: Promise<PibblFrameRecording>
```

Related API: [PibblFrameRecording](/reference/types/frame-recording/#pibblframerecording).

Resolves when retained frames are ready, or rejects on cancellation/failure.

[View source — packages/core/src/lib/recording/types.ts:50](/source/packages/core/src/lib/recording/types-ts/#L50)

</details>

<span id="api-PibblFrameRecordingSession-stop"></span>
<details>
<summary>stop</summary>


```ts
stop: () => void
```

Finish at the current elapsed time, retaining captured frames. Idempotent.

[View source — packages/core/src/lib/recording/types.ts:52](/source/packages/core/src/lib/recording/types-ts/#L52)

</details>

<span id="api-PibblFrameRecordingSession-cancel"></span>
<details>
<summary>cancel</summary>


```ts
cancel: () => void
```

Discard an active recording and release its resources. Idempotent.

[View source — packages/core/src/lib/recording/types.ts:54](/source/packages/core/src/lib/recording/types-ts/#L54)

</details>

<span id="api-PibblRecordedFrameInfo"></span>

### PibblRecordedFrameInfo

Metadata for one immutable RGBA bitmap in physical backing pixels.

```ts
interface PibblRecordedFrameInfo
```

Related API: [PibblRecordedFrameInfo](/reference/types/frame-recording/#pibblrecordedframeinfo).

#### See also

[PibblRecordedFrame](/reference/types/frame-recording/#pibblrecordedframe)

[View source — packages/core/src/lib/recording/types.ts:60](/source/packages/core/src/lib/recording/types-ts/#L60)

#### Properties and methods

<span id="api-PibblRecordedFrameInfo-renderGeneration"></span>
<details>
<summary>renderGeneration</summary>


```ts
readonly renderGeneration: number
```

Root render generation whose committed bitmap was copied.

[View source — packages/core/src/lib/recording/types.ts:62](/source/packages/core/src/lib/recording/types-ts/#L62)

</details>

<span id="api-PibblRecordedFrameInfo-timestamp"></span>
<details>
<summary>timestamp</summary>


```ts
readonly timestamp: number
```

Milliseconds since capture began; the initial frame is timestamp zero.

[View source — packages/core/src/lib/recording/types.ts:64](/source/packages/core/src/lib/recording/types-ts/#L64)

</details>

<span id="api-PibblRecordedFrameInfo-width"></span>
<details>
<summary>width</summary>


```ts
readonly width: number
```

Bitmap width in physical backing pixels.

[View source — packages/core/src/lib/recording/types.ts:66](/source/packages/core/src/lib/recording/types-ts/#L66)

</details>

<span id="api-PibblRecordedFrameInfo-height"></span>
<details>
<summary>height</summary>


```ts
readonly height: number
```

Bitmap height in physical backing pixels.

[View source — packages/core/src/lib/recording/types.ts:68](/source/packages/core/src/lib/recording/types-ts/#L68)

</details>

<span id="api-PibblRecordedFrame"></span>

### PibblRecordedFrame

A caller-owned copy of one frame's RGBA8 bytes.

```ts
interface PibblRecordedFrame extends PibblRecordedFrameInfo
```

Related API: [PibblRecordedFrame](/reference/types/frame-recording/#pibblrecordedframe), [PibblRecordedFrameInfo](/reference/types/frame-recording/#pibblrecordedframeinfo).

#### See also

[PibblRecordedFrameInfo](/reference/types/frame-recording/#pibblrecordedframeinfo)

[View source — packages/core/src/lib/recording/types.ts:74](/source/packages/core/src/lib/recording/types-ts/#L74)

#### Properties and methods

<span id="api-PibblRecordedFrame-data"></span>
<details>
<summary>data</summary>


```ts
readonly data: Uint8ClampedArray<ArrayBuffer>
```

Independent RGBA8 bytes; mutations never affect retained pixels.

[View source — packages/core/src/lib/recording/types.ts:76](/source/packages/core/src/lib/recording/types-ts/#L76)

</details>

<span id="api-PibblRecordedFrame-renderGeneration"></span>
<details>
<summary>renderGeneration</summary>


```ts
readonly renderGeneration: number
```

Root render generation whose committed bitmap was copied.

[View source — packages/core/src/lib/recording/types.ts:62](/source/packages/core/src/lib/recording/types-ts/#L62)

</details>

<span id="api-PibblRecordedFrame-timestamp"></span>
<details>
<summary>timestamp</summary>


```ts
readonly timestamp: number
```

Milliseconds since capture began; the initial frame is timestamp zero.

[View source — packages/core/src/lib/recording/types.ts:64](/source/packages/core/src/lib/recording/types-ts/#L64)

</details>

<span id="api-PibblRecordedFrame-width"></span>
<details>
<summary>width</summary>


```ts
readonly width: number
```

Bitmap width in physical backing pixels.

[View source — packages/core/src/lib/recording/types.ts:66](/source/packages/core/src/lib/recording/types-ts/#L66)

</details>

<span id="api-PibblRecordedFrame-height"></span>
<details>
<summary>height</summary>


```ts
readonly height: number
```

Bitmap height in physical backing pixels.

[View source — packages/core/src/lib/recording/types.ts:68](/source/packages/core/src/lib/recording/types-ts/#L68)

</details>

<span id="api-PibblFrameRecording"></span>

### PibblFrameRecording

Retained worker-owned frames; explicitly dispose after use.

```ts
interface PibblFrameRecording
```

Related API: [PibblFrameRecording](/reference/types/frame-recording/#pibblframerecording).

#### See also

[PibblFrameRecordingSession](/reference/types/frame-recording/#pibblframerecordingsession)

[View source — packages/core/src/lib/recording/types.ts:82](/source/packages/core/src/lib/recording/types-ts/#L82)

#### Properties and methods

<span id="api-PibblFrameRecording-duration"></span>
<details>
<summary>duration</summary>


```ts
readonly duration: number
```

Actual recording length in milliseconds, including the final still hold.

[View source — packages/core/src/lib/recording/types.ts:84](/source/packages/core/src/lib/recording/types-ts/#L84)

</details>

<span id="api-PibblFrameRecording-frames"></span>
<details>
<summary>frames</summary>


```ts
readonly frames: readonly PibblRecordedFrameInfo[]
```

Related API: [PibblRecordedFrameInfo](/reference/types/frame-recording/#pibblrecordedframeinfo).

Immutable metadata ordered by ascending timestamp.

[View source — packages/core/src/lib/recording/types.ts:86](/source/packages/core/src/lib/recording/types-ts/#L86)

</details>

<span id="api-PibblFrameRecording-readFrame"></span>
<details>
<summary>readFrame</summary>


```ts
readFrame: (index: number) => Promise<PibblRecordedFrame>
```

Related API: [PibblRecordedFrame](/reference/types/frame-recording/#pibblrecordedframe).

Copy one frame without transferring ownership of stored pixels.

##### Parameters

- **`index`** — Zero-based recorded frame index.

##### Returns

A caller-owned pixel copy and its metadata.

[View source — packages/core/src/lib/recording/types.ts:91](/source/packages/core/src/lib/recording/types-ts/#L91)

</details>

<span id="api-PibblFrameRecording-dispose"></span>
<details>
<summary>dispose</summary>


```ts
dispose: () => void
```

Release the worker, stored pixels, and pending reads/exports. Idempotent.

[View source — packages/core/src/lib/recording/types.ts:93](/source/packages/core/src/lib/recording/types-ts/#L93)

</details>

<span id="api-PibblGifExportOptions"></span>

### PibblGifExportOptions

GIF encoding options; encoding never changes the retained recording.

```ts
interface PibblGifExportOptions
```

Related API: [PibblGifExportOptions](/reference/types/frame-recording/#pibblgifexportoptions).

#### See also

[PibblFrameRecording](/reference/types/frame-recording/#pibblframerecording)

[View source — packages/core/src/lib/recording/types.ts:99](/source/packages/core/src/lib/recording/types-ts/#L99)

#### Properties and methods

<span id="api-PibblGifExportOptions-width"></span>
<details>
<summary>width (optional)</summary>


```ts
width?: number | undefined
```

Output width in pixels; omitted preserves source width or the specified height's aspect ratio.

[View source — packages/core/src/lib/recording/types.ts:101](/source/packages/core/src/lib/recording/types-ts/#L101)

</details>

<span id="api-PibblGifExportOptions-height"></span>
<details>
<summary>height (optional)</summary>


```ts
height?: number | undefined
```

Output height in pixels; omitted preserves source height or the specified width's aspect ratio.

[View source — packages/core/src/lib/recording/types.ts:103](/source/packages/core/src/lib/recording/types-ts/#L103)

</details>

<span id="api-PibblGifExportOptions-maxColors"></span>
<details>
<summary>maxColors (optional)</summary>


```ts
maxColors?: number | undefined
```

Maximum palette entries, including transparency when no background is supplied; integer 2–256, default 256.

[View source — packages/core/src/lib/recording/types.ts:105](/source/packages/core/src/lib/recording/types-ts/#L105)

</details>

<span id="api-PibblGifExportOptions-palette"></span>
<details>
<summary>palette (optional)</summary>


```ts
palette?: readonly string[] | undefined
```

Exact opaque CSS palette colors. Replaces automatic palette selection; must fit maxColors.

[View source — packages/core/src/lib/recording/types.ts:107](/source/packages/core/src/lib/recording/types-ts/#L107)

</details>

<span id="api-PibblGifExportOptions-dithering"></span>
<details>
<summary>dithering (optional)</summary>


```ts
dithering?: boolean | undefined
```

Apply Floyd–Steinberg error diffusion; defaults to false.

[View source — packages/core/src/lib/recording/types.ts:109](/source/packages/core/src/lib/recording/types-ts/#L109)

</details>

<span id="api-PibblGifExportOptions-quantizationSampleFactor"></span>
<details>
<summary>quantizationSampleFactor (optional)</summary>


```ts
quantizationSampleFactor?: number | undefined
```

NeuQuant sampling factor, integer 1–30; 1 spends most effort, default 10. Ignored with a supplied palette.

[View source — packages/core/src/lib/recording/types.ts:111](/source/packages/core/src/lib/recording/types-ts/#L111)

</details>

<span id="api-PibblGifExportOptions-paletteSampleCount"></span>
<details>
<summary>paletteSampleCount (optional)</summary>


```ts
paletteSampleCount?: number | undefined
```

Maximum pixels sampled for automatic palette selection across up to 32 frames; default 262144. Ignored with a supplied palette.

[View source — packages/core/src/lib/recording/types.ts:113](/source/packages/core/src/lib/recording/types-ts/#L113)

</details>

<span id="api-PibblGifExportOptions-frameRate"></span>
<details>
<summary>frameRate (optional)</summary>


```ts
frameRate?: number | undefined
```

Output sampling frequency; defaults to 25. Must be at most 100.

[View source — packages/core/src/lib/recording/types.ts:115](/source/packages/core/src/lib/recording/types-ts/#L115)

</details>

<span id="api-PibblGifExportOptions-repeatCount"></span>
<details>
<summary>repeatCount (optional)</summary>


```ts
repeatCount?: number | undefined
```

Zero loops forever; omitted plays once; positive values repeat that many times.

[View source — packages/core/src/lib/recording/types.ts:117](/source/packages/core/src/lib/recording/types-ts/#L117)

</details>

<span id="api-PibblGifExportOptions-background"></span>
<details>
<summary>background (optional)</summary>


```ts
background?: string | undefined
```

Optional opaque CSS color used to flatten partial alpha before quantization.

[View source — packages/core/src/lib/recording/types.ts:119](/source/packages/core/src/lib/recording/types-ts/#L119)

</details>

<span id="api-PibblGifExportOptions-signal"></span>
<details>
<summary>signal (optional)</summary>


```ts
signal?: AbortSignal | undefined
```

Related API: [signal](/reference/functions/signal/).

Abort encoding while preserving the recording for another export.

[View source — packages/core/src/lib/recording/types.ts:121](/source/packages/core/src/lib/recording/types-ts/#L121)

</details>

<span id="api-PibblGifExportOptions-onProgress"></span>
<details>
<summary>onProgress (optional)</summary>


```ts
onProgress?: ((progress: number) => void) | undefined
```

Progress from zero to one, delivered between bounded worker batches.

##### Parameters

- **`progress`** — Fraction of output frames encoded.

[View source — packages/core/src/lib/recording/types.ts:125](/source/packages/core/src/lib/recording/types-ts/#L125)

</details>

<span id="api-PibblRenderCompletion"></span>

### PibblRenderCompletion

A completed root-render attempt. Failed generations were attempted, not committed.
Generations identify renders of one mounted root; they are not global IDs.

```ts
type PibblRenderCompletion = | {
      /** The root bitmap and render-owned state committed successfully. */
      readonly status: "committed";
      /** Monotonically increasing generation of this root's committed render. */
      readonly generation: number;
    }
  | {
      /** The attempted render failed and supplies no committed pixel evidence. */
      readonly status: "failed";
      /** Attempted generation of this root; it must not identify recorded pixels. */
      readonly generation: number;
    }
```

Related API: [PibblRenderCompletion](/reference/types/frame-recording/#pibblrendercompletion).

#### See also

[PibblFrameRecordingOptions](/reference/types/frame-recording/#pibblframerecordingoptions)

[View source — packages/core/src/lib/recording/types.ts:29](/source/packages/core/src/lib/recording/types-ts/#L29)

#### Properties and methods

<span id="api-PibblRenderCompletion-status"></span>
<details>
<summary>status</summary>


```ts
readonly status: "committed" | "failed"
```

The root bitmap and render-owned state committed successfully.
The attempted render failed and supplies no committed pixel evidence.

[View source — packages/core/src/lib/recording/types.ts:32](/source/packages/core/src/lib/recording/types-ts/#L32)

</details>

<span id="api-PibblRenderCompletion-generation"></span>
<details>
<summary>generation</summary>


```ts
readonly generation: number
```

Monotonically increasing generation of this root's committed render.
Attempted generation of this root; it must not identify recorded pixels.

[View source — packages/core/src/lib/recording/types.ts:34](/source/packages/core/src/lib/recording/types-ts/#L34)

</details>

## Implementation guidance for agents

Read the [Authoring, signals, and lifecycle companion](/agents/topics/lifecycle/) for ownership, adaptation, failure modes, and verification. [Agent start](/agents/) provides the version-selection workflow.

## Complete minimal examples

- [Record committed frames and export a GIF](/minimal-examples/recording/record-frames/): Capture a live Canvas color change, read frame metadata and pixels, export a GIF and release owned resources. [Plain source](/minimal/recording/record-frames.ts)
## Documentation version

Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.
