Egress API

Use LiveKit's egress service to record or livestream a Room.

API

The Egress API is available within our server SDKs and CLI:

important:

Requests to the Egress API need the roomRecord permission on the access token.

You can also use curl to interact with the Egress APIs. To do so, POST the arguments in JSON format to:

https://<your-livekit-host>/twirp/livekit.Egress/<MethodName>

For example:

% curl -X POST https://<your-livekit-host>/twirp/livekit.Egress/StartRoomCompositeEgress \
-H 'Authorization: Bearer <livekit-access-token>' \
-H 'Content-Type: application/json' \
-d '{"room_name": "your-room", "segments": {"filename_prefix": "your-hls-playlist.m3u8", "s3": {"access_key": "<key>", "secret": "<secret>", "bucket": "<bucket>", "region": "<bucket-region>"}}}'
{"egress_id":"EG_MU4QwhXUhWf9","room_id":"<room-id>","room_name":"your-room","status":"EGRESS_STARTING"...}
tip:

All RPC definitions and options can be found here.

StartRoomCompositeEgress

Starts a new Composite Recording using a web browser as the rendering engine.

ParameterTypeRequiredDescription
room_namestringyesname of room to record
layoutstringlayout parameter that is passed to the template
audio_onlybooltrue if resulting output should only contain audio
video_onlybooltrue if resulting output should only contain video
custom_base_urlstringURL to the page that would composite tracks, uses embedded templates if left blank
file_outputsEncodedFileOutput[]output to MP4 file. currently only supports a single entry
segment_outputsSegmentedFileOutput[]output to HLS segments. currently only supports a single entry
stream_outputsStreamOutput[]output to a stream. currently only supports a single entry, though it could includ multiple destination URLs
image_outputsImageOutput[]output to a succession of snapshot images taken at a given interval (thumbnails). Currently only supports a single entry.
presetEncodingOptionsPresetencoding preset to use. only one of preset or advanced could be set
advancedEncodingOptionsadvanced encoding options. only one of preset or advanced could be set

StartTrackCompositeEgress

Starts a new Track Composite

ParameterTypeRequiredDescription
room_namestringyesname of room to record
audio_track_idstringID of audio track to composite
video_track_idstringID of video track to composite
file_outputsEncodedFileOutput[]output to MP4 file. currently only supports a single entry
segment_outputsSegmentedFileOutput[]output to HLS segments. currently only supports a single entry
stream_outputsStreamOutput[]output to a stream. currently only supports a single entry, though it could includ multiple destination URLs
image_outputsImageOutput[]output to a succession of snapshot images taken at a given interval (thumbnails). Currently only supports a single entry.
presetEncodingOptionsPresetencoding preset to use. only one of preset or advanced could be set
advancedEncodingOptionsadvanced encoding options. only one of preset or advanced could be set

StartTrackEgress

Starts a new Track Egress

ParameterTypeRequiredDescription
room_namestringyesname of room to record
track_idstringlayout parameter that is passed to the template
fileDirectFileOutputonly one of file or websocket_url can be set
websocket_urlstringurl to websocket to receive audio output. only one of file or websocket_url can be set

StartWebEgress

Starts a new Web Egress

ParameterTypeRequiredDescription
urlstringyesURL of the web page to record
audio_onlybooltrue if resulting output should only contain audio
video_onlybooltrue if resulting output should only contain video
file_outputsEncodedFileOutput[]output to MP4 file. currently only supports a single entry
segment_outputsSegmentedFileOutput[]output to HLS segments. currently only supports a single entry
stream_outputsStreamOutput[]output to a stream. currently only supports a single entry, though it could includ multiple destination URLs
image_outputsImageOutput[]output to a succession of snapshot images taken at a given interval (thumbnails). Currently only supports a single entry.
presetEncodingOptionsPresetencoding preset to use. only one of preset or advanced could be set
advancedEncodingOptionsadvanced encoding options. only one of preset or advanced could be set

UpdateLayout

Used to change the web layout on an active RoomCompositeEgress.

ParameterTypeRequiredDescription
egress_idstringyesEgress ID to update
layoutstringyeslayout to update to
const info = await egressClient.updateLayout(egressID, 'grid-light');

UpdateStream

Used to add or remove stream urls from an active stream

Note: you can only add outputs to an Egress that was started with stream_outputs set.

ParameterTypeRequiredDescription
egress_idstringyesEgress ID to update
add_output_urlsstring[]URLs to add to the egress as output destinations
remove_output_urlsstring[]URLs to remove from the egress
const streamOutput = new StreamOutput({
protocol: StreamProtocol.RTMP,
urls: ['rtmp://live.twitch.tv/app/<stream-key>'],
});
var info = await egressClient.startRoomCompositeEgress('my-room', { stream: streamOutput });
const streamEgressID = info.egressId;
info = await egressClient.updateStream(streamEgressID, [
'rtmp://a.rtmp.youtube.com/live2/stream-key',
]);

ListEgress

Used to list active egress. Does not include completed egress.

const res = await egressClient.listEgress();

StopEgress

Stops an active egress.

const info = await egressClient.stopEgress(egressID);

Types

EncodedFileOutput

FieldTypeDescription
filepathstringdefault {room_name}-{time}
disable_manifestboolby default, Egress outputs a {filepath}.json with metadata of the file
s3S3Uploadset if uploading to S3 compatible storage. only one storage output can be set
gcpGCPUploadset if uploading to GCP
azureAzureBlobUploadset if uploading to Azure
aliOSSAliOSSUploadset if uploading to AliOSS

DirectFileOutput

FieldTypeDescription
filepathstringdefault {track_id}-{time}
disable_manifestboolby default, Egress outputs a {filepath}.json with metadata of the file
s3S3Uploadset if uploading to S3 compatible storage. only one storage output can be set
gcpGCPUploadset if uploading to GCP
azureAzureBlobUploadset if uploading to Azure
aliOSSAliOSSUploadset if uploading to AliOSS

SegmentedFileOutput

FieldTypeDescription
filename_prefixstringprefix used in each segment (include any paths here)
playlist_namestringname of the m3u8 playlist. when empty, matches filename_prefix
segment_durationuint32length of each segment (defaults to 4s)
filename_suffixSegmentedFileSuffixINDEX (1, 2, 3) or TIMESTAMP (in UTC)
disable_manifestbool
s3S3Uploadset if uploading to S3 compatible storage. only one storage output can be set
gcpGCPUploadset if uploading to GCP
azureAzureBlobUploadset if uploading to Azure
aliOSSAliOSSUploadset if uploading to AliOSS

StreamOutput

FieldTypeDescription
protocolSreamProtocol(optional) only RTMP is supported
urlsstring[]list of URLs to send stream to

ImageOutput

FieldTypeDescription
capture_intervaluint32time in seconds between each snapshot
widthint32width of the snapshot images (optional, the original width will be used if not provided)
heightint32height of the snapshot images (optional, the original width will be used if not provided)
filename_prefixstringprefix used in each image filename (include any paths here)
filename_suffixImageFileSuffixINDEX (1, 2, 3) or TIMESTAMP (in UTC)
image_codecImageCodecIC_DEFAULT or IC_JPEG (optional, both options will cause JPEGs to be generated currently)
disable_manifestboolby default, Egress outputs a {filepath}.json with a list of exported snapshots
s3S3Uploadset if uploading to S3 compatible storage. only one storage output can be set
gcpGCPUploadset if uploading to GCP
azureAzureBlobUploadset if uploading to Azure
aliOSSAliOSSUploadset if uploading to AliOSS

S3Upload

FieldTypeDescription
access_keystring
secretstringS3 secret key
bucketstringdestination bucket
regionstringregion of the S3 bucket (optional)
endpointstringURL to use for S3 (optional)
force_path_styleboolleave bucket in the path and never to sub-domain (optional)
metadatamap<string, string>metadata key/value pairs to store (optional)
taggingstring(optional)
proxyProxyConfigProxy server to use when uploading(optional)

GCPUpload

FieldTypeDescription
credentialsstringContents of credentials.json
bucketstringdestination bucket
proxyProxyConfigProxy server to use when uploading(optional)

AzureBlobUpload

FieldTypeDescription
account_namestring
account_keystring
container_namestringdestination container

AliOSSUpload

FieldTypeDescription
access_keystring
secretstring
bucketstring
regionstring
endpointstring

EncodingOptions

FieldTypeDescription
widthint32
heightint32
depthint32default 24
framerateint32default 30
audio_codecAudioCodecdefault AAC
audio_bitrateint32128
audio_frequencyint3244100
video_codecVideoCodecdefault H264_MAIN
video_bitrateint32default 4500
key_frame_intervalint32default 4s

EncodingOptionsPreset

Enum, valid values:

  • H264_720P_30: 0
  • H264_720P_60: 1
  • H264_1080P_30: 2
  • H264_1080P_60: 3
  • PORTRAIT_H264_720P_30: 4
  • PORTRAIT_H264_720P_60: 5
  • PORTRAIT_H264_1080P_30: 6
  • PORTRAIT_H264_1080P_60: 7

ProxyConfig

For S3 and GCP, you can specify a proxy server for Egress to use when uploading files.

This can be helpful to avoid network restrictions on the destination buckets.

FieldTypeDescription
urlstringURL of the proxy
usernamestringusername for basic auth (optional)
passwordstringpassword for basic auth (optional)