recording
Server-side room recording with LiveKit Egress — composite and track-based recording, S3 storage, recording metadata in Postgres. Use this skill when the user says "add recording", "record room", "record video", "record meeting", "egress recording", or "save recording".
What this skill does
# Recording (LiveKit Egress)
Server-side room recording using [LiveKit Egress](https://docs.livekit.io/egress/). Supports both composite recording (all participants in a single layout) and track-based recording (individual participant tracks). Recordings are stored to S3-compatible storage via `EncodedFileOutput` and tracked in Postgres with full metadata.
## Prerequisites
- Next.js app with `src/` directory and App Router
- `video-room` skill applied (provides `livekit-server-sdk`, LiveKit server configuration)
- `storage` skill applied (provides S3-compatible storage with bucket)
- `queue` skill applied (provides Inngest for async job tracking)
- `env-config` skill applied (provides Zod env validation)
## Installation
No additional packages required. Uses `livekit-server-sdk` from the `video-room` skill and `@aws-sdk/client-s3` from the `storage` skill.
## Environment Variables
Uses existing environment variables from dependencies:
```env
# LiveKit (from video-room)
LIVEKIT_API_KEY=your_api_key
LIVEKIT_API_SECRET=your_api_secret
NEXT_PUBLIC_LIVEKIT_URL=wss://your-project.livekit.cloud
# S3 Storage (from storage)
S3_ENDPOINT=http://localhost:9000
S3_ACCESS_KEY=rustfsadmin
S3_SECRET_KEY=rustfsadmin
S3_BUCKET=uploads
S3_REGION=us-east-1
```
Add to `src/env.ts` server schema (if not already present from `video-room`):
```typescript
LIVEKIT_API_KEY: z.string().min(1).optional(),
LIVEKIT_API_SECRET: z.string().min(1).optional(),
```
And client schema:
```typescript
NEXT_PUBLIC_LIVEKIT_URL: z.string().url().optional(),
```
## What Gets Created
```
src/
├── lib/
│ ├── video/
│ │ ├── recording.ts # Server functions: start, stop, list recordings
│ │ └── types-recording.ts # RecordingConfig, RecordingResult, RecordingStatus
│ └── db/
│ └── schema/
│ └── recordings.ts # Drizzle schema: recordings table
└── app/
└── api/
└── video/
└── recordings/
├── route.ts # POST start recording, GET list recordings
└── [id]/
└── route.ts # GET recording status/download URL, PATCH stop, DELETE
```
## Setup Steps
### Step 1: Create `src/lib/video/types-recording.ts`
```typescript
export type RecordingLayout = "speaker" | "grid" | "single-speaker";
export type RecordingResolution = {
width: number;
height: number;
};
export const RECORDING_PRESETS = {
"720p": { width: 1280, height: 720 },
"1080p": { width: 1920, height: 1080 },
"480p": { width: 854, height: 480 },
} as const;
export type RecordingPreset = keyof typeof RECORDING_PRESETS;
export type RecordingCodec = "h264" | "vp8";
export type RecordingConfig = {
roomName: string;
layout?: RecordingLayout;
resolution?: RecordingPreset;
codec?: RecordingCodec;
audioBitrate?: number;
videoBitrate?: number;
/** If true, records individual tracks instead of composite */
trackBased?: boolean;
/** Specific track SID to record (for track-based recording) */
trackSid?: string;
};
export type RecordingStatusValue =
| "starting"
| "active"
| "stopping"
| "completed"
| "failed";
export type RecordingResult = {
id: string;
roomName: string;
egressId: string;
status: RecordingStatusValue;
startedAt: Date;
stoppedAt: Date | null;
fileUrl: string | null;
duration: number | null;
fileSize: number | null;
};
export type StartRecordingResponse = {
recordingId: string;
egressId: string;
status: RecordingStatusValue;
};
export type StopRecordingResponse = {
recordingId: string;
egressId: string;
status: RecordingStatusValue;
fileUrl: string | null;
duration: number | null;
};
```
### Step 2: Create `src/lib/db/schema/recordings.ts`
```typescript
import {
pgTable,
text,
timestamp,
uuid,
integer,
real,
} from "drizzle-orm/pg-core";
export const recordings = pgTable("recordings", {
id: uuid("id").primaryKey().defaultRandom(),
roomName: text("room_name").notNull(),
roomSid: text("room_sid"),
egressId: text("egress_id").notNull(),
status: text("status", {
enum: ["starting", "active", "stopping", "completed", "failed"],
})
.notNull()
.default("starting"),
layout: text("layout", {
enum: ["speaker", "grid", "single-speaker"],
}).default("grid"),
codec: text("codec").default("h264"),
resolution: text("resolution").default("1080p"),
startedAt: timestamp("started_at", { withTimezone: true })
.notNull()
.defaultNow(),
stoppedAt: timestamp("stopped_at", { withTimezone: true }),
fileUrl: text("file_url"),
storageKey: text("storage_key"),
fileSize: integer("file_size"),
duration: real("duration"),
userId: text("user_id").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow(),
});
export type Recording = typeof recordings.$inferSelect;
export type NewRecording = typeof recordings.$inferInsert;
```
### Step 3: Add export to `src/lib/db/schema/index.ts`
```typescript
export * from "./recordings";
```
### Step 4: Create `src/lib/video/recording.ts`
> **Important**: Use `EncodingOptionsPreset` (enum values) for encoding options instead of constructing partial `EncodingOptions` objects. The `EncodingOptions` interface requires many fields (depth, framerate, audioCodec, etc.) and partial objects will fail type-checking. Use `DirectFileOutput` (not `EncodedFileOutput`) for track-based egress — `startTrackEgress` requires `DirectFileOutput | string`.
```typescript
import {
EgressClient,
EncodedFileOutput,
EncodedFileType,
DirectFileOutput,
EncodingOptionsPreset,
} from "livekit-server-sdk";
import { db } from "@/lib/db";
import { recordings } from "@/lib/db/schema/recordings";
import { eq, desc, and } from "drizzle-orm";
import type {
RecordingConfig,
RecordingStatusValue,
StartRecordingResponse,
StopRecordingResponse,
} from "./types-recording";
import type { Recording } from "@/lib/db/schema/recordings";
import type { RecordingPreset } from "./types-recording";
function getEgressClient(): EgressClient {
const livekitUrl = process.env.NEXT_PUBLIC_LIVEKIT_URL;
const apiKey = process.env.LIVEKIT_API_KEY;
const apiSecret = process.env.LIVEKIT_API_SECRET;
if (!livekitUrl || !apiKey || !apiSecret) {
throw new Error(
"Missing NEXT_PUBLIC_LIVEKIT_URL, LIVEKIT_API_KEY, or LIVEKIT_API_SECRET"
);
}
// Convert wss:// to https:// for REST API
const httpUrl = livekitUrl.replace("wss://", "https://").replace("ws://", "http://");
return new EgressClient(httpUrl, apiKey, apiSecret);
}
function getEncodingPreset(resolution: RecordingPreset | undefined): EncodingOptionsPreset {
switch (resolution) {
case "480p":
return EncodingOptionsPreset.H264_720P_30; // closest available preset
case "720p":
return EncodingOptionsPreset.H264_720P_30;
case "1080p":
return EncodingOptionsPreset.H264_1080P_30;
default:
return EncodingOptionsPreset.H264_1080P_30;
}
}
function buildFileOutput(roomName: string, fileType: EncodedFileType): EncodedFileOutput {
const bucket = process.env.S3_BUCKET ?? "uploads";
const timestamp = Date.now();
const filepath = `recordings/${roomName}/${timestamp}`;
const output = new EncodedFileOutput({
fileType,
filepath,
output: {
case: "s3",
value: {
accessKey: process.env.S3_ACCESS_KEY ?? "",
secret: process.env.S3_SECRET_KEY ?? "",
region: process.env.S3_REGION ?? "us-east-1",
bucket,
endpoint: process.env.S3_ENDPOINT ?? "",
forcePathStyle: true,
},
},
});
return output;
}
function buildDirectFileOutput(roomName: string): DirectFileOutput {
const bucket = process.env.S3_BUCKET ?? "uploads";
const timestamp = Date.now();
const filepath = `recordings/${roomName}/${timestamp}`;
return new DirectFileOutput({
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.