• Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Export and record WebRTC sessions and tracks
The LiveKit icon, the name of the repository and some sample code in the background.

LiveKit Egress

WebRTC is fantastic for last-mile media delivery, but interoperability with other services can be challenging. An application may want to do things like store a session for future playback, relay a stream to a CDN, or process a track through a transcription service – workflows where media travels through a different system or protocol. LiveKit Egress is the solution to these interoperability challenges. It provides a consistent set of APIs that gives you universal export of your LiveKit sessions and tracks.

Capabilities

  1. Room composite for exporting an entire room.
  2. Web egress for recordings that aren't attached to a single LiveKit room.
  3. Track composite for exporting synchronized tracks of a single participant.
  4. Track egress for exporting individual tracks.

Depending on your request type, the egress service will either launch Chrome using a web template (room composite requests) or a supplied url (web requests), or it will use the Go SDK directly (track and track composite requests). Irrespective of method used, when moving between protocols, containers or encodings, LiveKit's egress service will automatically transcode streams for you using GStreamer.

Supported Output

Egress Type MP4 File OGG File WebM File HLS (TS Segments) RTMP(s) Stream WebSocket Stream
Room Composite βœ… βœ… βœ… βœ…
Web βœ… βœ… βœ… βœ…
Track Composite βœ… βœ… βœ… βœ…
Track βœ… βœ… βœ… βœ…

Files can be uploaded to any S3 compatible storage, Azure, or GCP.

Documentation

Full docs available here

Config

The Egress service takes a yaml config file:

# required fields
api_key: livekit server api key. LIVEKIT_API_KEY env can be used instead
api_secret: livekit server api secret. LIVEKIT_API_SECRET env can be used instead
ws_url: livekit server websocket url. LIVEKIT_WS_URL can be used instead
redis:
  address: must be the same redis address used by your livekit server
  username: redis username
  password: redis password
  db: redis db

# optional fields
health_port: if used, will open an http port for health checks
prometheus_port: port used to collect prometheus metrics. Used for autoscaling
logging:
  level: debug, info, warn, or error (default info)
  json: true
template_base: can be used to host custom templates (default https://egress-composite.livekit.io)
insecure: can be used to connect to an insecure websocket (default false)
cpu_cost: # optionally override cpu cost estimation, used when accepting or denying requests
  room_composite_cpu_cost: 3.0
  web_cpu_cost: 3.0
  track_composite_cpu_cost: 2.0
  track_cpu_cost: 1.0
session_limits: # optional egress duration limits - once hit, egress will end with status EGRESS_LIMIT_REACHED
  file_output_max_duration: 1h
  stream_output_max_duration: 90m
  segment_output_max_duration: 3h

# file upload config - only one of the following. Can be overridden per request
s3:
  access_key: AWS_ACCESS_KEY_ID env or IAM role can be used instead
  secret: AWS_SECRET_ACCESS_KEY env or IAM role can be used instead
  region: AWS_DEFAULT_REGION env or IAM role can be used instead
  endpoint: (optional) custom endpoint
  bucket: bucket to upload files to
azure:
  account_name: AZURE_STORAGE_ACCOUNT env can be used instead
  account_key: AZURE_STORAGE_KEY env can be used instead
  container_name: container to upload files to
gcp:
  credentials_json: GOOGLE_APPLICATION_CREDENTIALS env can be used instead
  bucket: bucket to upload files to
alioss:
  access_key: Ali OSS AccessKeyId
  secret: Ali OSS AccessKeySecret
  region: Ali OSS region
  endpoint: (optional) custom endpoint
  bucket: bucket to upload files to

The config file can be added to a mounted volume with its location passed in the EGRESS_CONFIG_FILE env var, or its body can be passed in the EGRESS_CONFIG_BODY env var.

Filenames

The below templates can also be used in filename/filepath parameters:

Egress Type {room_id} {room_name} {time} {utc} {publisher_identity} {track_id} {track_type} {track_source}
Room Composite βœ… βœ… βœ… βœ…
Web βœ… βœ…
Track Composite βœ… βœ… βœ… βœ… βœ…
Track βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…
  • If no filename is provided with a request, one will be generated in the form of "{room_name}-{time}".
  • If your filename ends with a /, a file will be generated in that directory.
  • For 1/2/2006, 3:04:05.789 PM, {time} format would display "2006-01-02T150405", and {utc} format "20060102150405789"

Examples:

Request filename Resulting filename
"" testroom-2022-10-04T011306.mp4
"livekit-recordings/" livekit-recordings/testroom-2022-10-04T011306.mp4
"{room_name}/{time}" testroom/2022-10-04T011306.mp4
"{room_id}-{publisher_identity}.mp4" 10719607-f7b0-4d82-afe1-06b77e91fe12-david.mp4
"{track_type}-{track_source}-{track_id}" audio-microphone-TR_SKasdXCVgHsei.ogg

Running locally

These changes are not recommended for a production setup.

To run against a local livekit server, you'll need to do the following:

  • open /usr/local/etc/redis.conf and comment out the line that says bind 127.0.0.1
  • change protected-mode yes to protected-mode no in the same file
  • find your IP as seen by docker
    • ws_url needs to be set using the IP as Docker sees it
    • on linux, this should be 172.17.0.1
    • on mac or windows, run docker run -it --rm alpine nslookup host.docker.internal and you should see something like Name: host.docker.internal Address: 192.168.65.2

These changes allow the service to connect to your local redis instance from inside the docker container.

Create a directory to mount. In this example, we will use ~/egress-test.

Create a config.yaml in the above directory.

  • redis and ws_url should use the above IP instead of localhost
  • insecure should be set to true
log_level: debug
api_key: your-api-key
api_secret: your-api-secret
ws_url: ws://192.168.65.2:7880
insecure: true
redis:
  address: 192.168.65.2:6379

Then to run the service:

docker run --rm \
    -e EGRESS_CONFIG_FILE=/out/config.yaml \
    -v ~/egress-test:/out \
    livekit/egress

You can then use our cli to submit egress requests to your server.

FAQ

Can I store the files locally instead of uploading to cloud storage?

  • Yes, you can mount a volume with your docker run command (e.g. -v ~/livekit-egress:/out/), and use the mounted directory in your filenames (e.g. /out/my-recording.mp4)

I get a "no response from egress service" error when sending a request

  • Your livekit server cannot connect to an egress instance through redis. Make sure they are both able to reach the same redis db.
  • Each instance currently only accepts one RoomCompositeRequest at a time - if it's already in use, you'll need to deploy more instances or set up autoscaling.

I get a different error when sending a request

  • Make sure your egress, livekit, server sdk, and livekit-cli are all up to date.

I'm getting a broken (0 byte) mp4 file

  • This is caused by the process being killed - GStreamer needs to be properly shut down to close the file.
  • Make sure your instance has enough CPU and memory, and is being stopped correctly.

I'm seeing GStreamer warnings/errors. Is this normal?

  • GStreamer-CRITICAL **: 20:22:13.875: gst_mini_object_unref: assertion 'GST_MINI_OBJECT_REFCOUNT_VALUE (mini_object) > 0' failed
    • Occurs during audio-only egress - this is a gst bug, and is safe to ignore.
  • WARN flvmux ... Got backwards dts! (0:01:10.379000000 < 0:01:10.457000000)
    • Occurs when streaming to rtmp - safe to ignore. These warnings occur due to live sources being used for the flvmux. The dts difference should be small (under 150ms).

Can I run this without docker?

  • It's possible, but not recommended. To do so, you would need gstreamer and all the plugins installed, along with xvfb, and have a pulseaudio server running.

Testing and Development

To run the test against your own LiveKit rooms, a deployed LiveKit server with a secure websocket url is required. First, create egress/test/config.yaml:

log_level: debug
api_key: your-api-key
api_secret: your-api-secret
ws_url: wss://your-livekit-url.com
redis:
  address: 192.168.65.2:6379
room_name: your-room
room_only: false
web_only: false
track_composite_only: false
track_only: false
file_only: false
stream_only: false
segments_only: false
muting: false

Join a room using https://example.livekit.io or your own client, then run mage integration test/config.yaml. This will test recording different file types, output settings, and streams against your room.


LiveKit Ecosystem
Client SDKsComponents Β· JavaScript Β· Rust Β· iOS/macOS Β· Android Β· Flutter Β· Unity (web) Β· Python Β· React Native (beta)
Server SDKsNode.js Β· Golang Β· Ruby Β· Java/Kotlin Β· PHP (community) Β· Python (community)
ServicesLivekit server Β· Egress Β· Ingress
ResourcesDocs Β· Example apps Β· Cloud Β· Self-hosting Β· CLI

More Repositories

1

livekit

End-to-end stack for WebRTC. SFU media server and SDKs.
Go
9,214
star
2

agents

Build real-time multimodal AI applications πŸ€–πŸŽ™οΈπŸ“Ή
Python
750
star
3

client-sdk-js

LiveKit browser client SDK (javascript)
TypeScript
329
star
4

client-sdk-flutter

Flutter Client SDK for LiveKit
Dart
238
star
5

livekit-cli

Command line interface to LiveKit
Go
199
star
6

server-sdk-go

Client and server SDK for Golang
Go
189
star
7

client-sdk-swift

LiveKit Swift Client SDK. Easily build live audio or video experiences into your mobile app, game or website.
Swift
182
star
8

rust-sdks

LiveKit real-time and server SDKs for Rust
Rust
173
star
9

client-sdk-android

LiveKit SDK for Android
Kotlin
169
star
10

livekit-react

React component and library for LiveKit
TypeScript
169
star
11

components-js

Official open source React components and examples for building with LiveKit.
TypeScript
145
star
12

node-sdks

LiveKit real-time and server SDKs for Node.JS
TypeScript
124
star
13

client-sdk-react-native

TypeScript
98
star
14

python-sdks

LiveKit real-time and server SDKs for Python
Python
80
star
15

sip

SIP to WebRTC bridge for LiveKit
Go
76
star
16

protocol

LiveKit protocol. Protobuf definitions for LiveKit's signaling protocol
Go
69
star
17

ingress

Ingest streams (RTMP/WHIP) or files (HLS, MP4) to LiveKit WebRTC
Go
68
star
18

agents-playground

TypeScript
61
star
19

client-sdk-unity-web

Client SDK for Unity WebGL
C#
50
star
20

livekit-helm

LiveKit Helm charts
Smarty
47
star
21

livekit-recorder

Go
32
star
22

client-sdk-unity

C#
31
star
23

track-processors-js

TypeScript
29
star
24

server-sdk-kotlin

Kotlin
28
star
25

livekit-server-sdk-python

LiveKit Server SDK for Python
Python
25
star
26

psrpc

Go
22
star
27

client-example-swift

Example app for LiveKit Swift SDK πŸ‘‰ https://github.com/livekit/client-sdk-swift
Swift
21
star
28

server-sdk-ruby

LiveKit Server SDK for Ruby
Ruby
21
star
29

meet

Open source video conferencing app built on LiveKit Components, LiveKit Cloud, and Next.js.
TypeScript
16
star
30

client-unity-demo

Demo for LiveKit Unity SDK
C#
11
star
31

client-sdk-cpp

C++
11
star
32

WebRTC-swift

Swift package for WebRTC
Objective-C
10
star
33

livekit-docs

JavaScript
10
star
34

deploy

Resources for deploying LiveKit
Go
9
star
35

webrtc-vmaf

VMAF benchmarking tool for WebRTC codecs
Python
9
star
36

chrometester

A livekit tester to simulate a subscriber in a room, uses headless Chromium
JavaScript
8
star
37

gstreamer-publisher

Command-line app that publishes any GStreamer pipeline to LiveKit
Go
8
star
38

nats-test

benchmarking app that emulates our usage patterns
Go
7
star
39

mediatransportutil

Media transport utilities
Go
6
star
40

rtcscore-go

Library to calculate Mean Opinion Score(MOS)
Go
4
star
41

components-swift

Swift
4
star
42

signal-proxy

Go
3
star
43

client-example-collection-swift

A collection of small examples for the LiveKit Swift SDK πŸ‘‰ https://github.com/livekit/client-sdk-swift
Swift
3
star
44

webrtc-chrome

Fork of Google's WebRTC repo, with LiveKit patches.
C++
3
star
45

components-android

Kotlin
3
star
46

gst-plugins

Go
3
star
47

client-sdk-react-native-expo-plugin

TypeScript
2
star
48

webrtc-xcframework

Ruby
2
star
49

mageutil

Go
2
star
50

ios-test-apps

Swift
1
star
51

gstreamer

C
1
star
52

websocket-bridge

Send and Receive Media to LiveKit via WebSocket
Go
1
star