LiveKit LogoDocs

Server / Recording and Livestreaming / Track Egress

Track Egress

On this page

OverviewExport to cloud storageStream audio to WebSocket

Overview

TrackEgress is the simplest way to export individual tracks to cloud storage or a server via WebSocket.

Tracks are exported as is, without transcoding. The following containers will be used depending on track codec:

  • H.264: MP4
  • VP8: WebM
  • Opus: Ogg

Export to cloud storage

const output = {
fileType: EncodedFileType.MP4,
filepath: 'livekit-demo/track-test.mp4',
s3: {
accessKey: 'aws-access-key',
secret: 'aws-access-secret',
region: 'aws-region',
bucket: 'my-bucket'
}
};
const info = await egressClient.startTrackEgress('my-room', output, trackID);
const egressID = info.egressId;

Stream audio to WebSocket

You can add custom stream processing by starting a TrackEgress to your WebSocket server. This will give you a real-time streaming export of your audio tracks. (WebSocket streaming is only available for audio tracks).

The tracks will be exported as raw PCM data. This format is compatible with most transcription services.

  • Format: pcm_s16le
  • Content-Type: audio/x-raw
  • Sample rate: matches incoming, typically 48kHz

When a TrackEgressRequest is started with a WebSocket URL, we'll initiate a WebSocket session to the desired URL.

We'll send a combination of binary and text frames. Binary frames would contain audio data. Text frames will contain end user events on the tracks. For example: if the track was muted, you will receive the following:

{ "muted": true }

And when unmuted:

{ "muted": false }

The WebSocket connection will terminate when the track is unpublished (or if the participant leaves the room).

const info = await egressClient.startTrackEgress(
'my-room',
'wss://my-websocket-server.com',
trackID,
);
const egressID = info.egressId;

Previous

Chevron IconTrack Composite
LiveKit logo

Product

SFU

SDKs

Performance

Deployment