Skip to main content

Record audio and video

Capture session audio and video to your own storage with LiveKit Egress.

Overview

Audio recordings are automatically collected and uploaded to LiveKit Cloud for each session. These files are recorded after background voice cancellation (BVC) is applied and are available for playback and download on the Agent insights tab for the session.

If you need to have more fine-grained control over audio recordings and don't require BVC, or want to record both audio and video, you can use LiveKit Egress to capture audio and video directly to your storage provider. The simplest pattern is to start a room composite recorder when your agent joins the room.

from livekit import api
async def entrypoint(ctx: JobContext):
req = api.RoomCompositeEgressRequest(
room_name=ctx.room.name,
audio_only=True,
file_outputs=[
api.EncodedFileOutput(
file_type=api.EncodedFileType.OGG,
filepath="livekit/my-room-test.ogg",
s3=api.S3Upload(
bucket=os.getenv("AWS_BUCKET_NAME"),
region=os.getenv("AWS_REGION"),
access_key=os.getenv("AWS_ACCESS_KEY_ID"),
secret=os.getenv("AWS_SECRET_ACCESS_KEY"),
),
)
],
)
lkapi = api.LiveKitAPI()
await lkapi.egress.start_room_composite_egress(req)
await lkapi.aclose()
# ... continue with your agent logic
import {
LiveKitAPI,
EncodedFileOutput,
EncodedFileType,
EncodingOptionsPreset,
} from 'livekit-server-sdk';
// Reads LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET from the environment
// (a wss:// URL is converted to https:// internally).
const api = new LiveKitAPI();
const output = new EncodedFileOutput({
fileType: EncodedFileType.MP4,
filepath: 'livekit/my-room-test.mp4',
output: {
case: 's3',
value: {
accessKey: process.env.AWS_ACCESS_KEY_ID,
secret: process.env.AWS_SECRET_ACCESS_KEY,
bucket: process.env.AWS_BUCKET_NAME,
region: process.env.AWS_REGION,
forcePathStyle: true,
},
},
});
export default defineAgent({
entry: async (ctx: JobContext) => {
await api.egress.startRoomCompositeEgress(
ctx.room.name ?? 'open-room',
output,
{
layout: 'grid',
encodingOptions: EncodingOptionsPreset.H264_1080P_30,
audioOnly: false,
},
);
// ... continue with your agent logic
},
});

Additional resources

Related topics for capturing and reviewing session media.