RelayrtcDocs
Get started
Documentation
Streaming

Recording and VOD

Capture a broadcast and authorize private playback or MP4 downloads.

On this page

Recording captures a broadcast's canonical H.264/AAC program. It does not save isolated participant tracks or recover media from before capture. A recording worker and private storage must be available on the deployment.

Start capture

Obtain the required participant consent before acknowledging it in the policy. This backend helper takes the stream and broadcast IDs stored for an authorized event. region must match the deployment's storage region.

TypeScript
import { relay } from './relay.js'
 
export async function recordEvent(streamId: string, broadcastId: string, region: string) {
  return relay.streams.recordings.start(streamId, {
    broadcastId,
    policy: {
      mode: 'manual',
      maxDurationSeconds: 3600,
      retentionSeconds: 604800,
      region,
      allowPartial: false,
      exportMp4: true,
      segmentEvents: false,
      consentAcknowledged: true,
    },
  })
}

The consent flag records your application's acknowledgment; RelayRTC does not obtain consent by joining a room. Show an observed recording indicator to participants and provide the controls your workflow requires.

For automatic capture, save an automatic policy with streams.recordings.setPolicy before creating a broadcast. The run keeps that policy snapshot. Automatic recording reserves capacity during broadcast admission; insufficient capacity rejects the start rather than silently omitting capture.

Stop and finalize

Use recordings.get(recordingId) to follow queued, recording, finalizing, ready or failed. Call recordings.stop(recordingId) to stop capture; stopping its broadcast also ends capture. Wait for ready before offering playback or downloads.

Capture saves complete fragments and can include the latest two retained segments at startup. Gaps and source-generation changes can produce partial output. With allowPartial: false, incomplete output fails without playback access. Opting in allows recovery of available media, but does not guarantee a compatible MP4 export across source changes.

Authorize playback or downloads

After authenticating a viewer and checking access to the saved recording:

TypeScript
import { relay } from './relay.js'
 
export async function getRecordedPlayback(authorizedRecordingId: string) {
  const recording = await relay.recordings.get(authorizedRecordingId)
  if (recording.state !== 'ready') throw new Error('Recording is not ready')
  const playback = await relay.recordings.getPlayback(recording.id)
  const grant = await relay.assets.createAccessGrant(recording.assetId, {
    action: 'playback',
    ttlSeconds: 300,
  })
  return { playback, grant }
}

Provide these operations through application endpoints to BroadcastPlayer with mode="vod", using the private playback pattern. Return metadata and grants separately so the player can renew access. Grant renewal preserves position and pause state.

For MP4, first check the asset's formats, then issue a separate action: 'download' grant. A playback grant cannot download an export. Keep grant URLs out of logs; use HTTPS and a no-referrer policy. Storage remains private.

Retention and deletion

Retention begins when an asset becomes ready. Expiry and deletion revoke access before asynchronous storage cleanup finishes. Metadata and cumulative usage remain after objects are removed. Revoking existing asset links can preserve the recording while invalidating previously issued URLs; see asset access.

Defaults allow four in-flight recordings globally, two per environment and 512 MiB of objects per recording. MP4 export consumes part of that budget. A duration or storage cap can stop capture; empty output fails.

Recorded seconds, finalization elapsed seconds, stored bytes and storage byte-seconds are separate measurements. They do not measure CPU time or audience delivery. Use recording.ready and failure webhooks for application workflows, and reload the resource before publishing a result.

See recording REST APIs, Node methods and React recording state.