abundant-father-33863
04/01/2026, 12:49 PMtall-airline-16756
04/01/2026, 12:49 PMtall-airline-16756
04/01/2026, 12:50 PMS3Upload object with AccessKey, Secret, Bucket, and Region.
1. Convert the uploaded file to MP3.
◦ Post-process the file you get from egress (usually OGG/Opus or MP4 audio) using FFmpeg to produce MP3.
◦ Automate conversion with an AWS Lambda triggered by S3 object creation:
▪︎ Lambda downloads the egress file, runs FFmpeg to transcode to MP3, then stores the MP3 back to the target S3 location (or a separate bucket/folder).
Alternate: encode to MP3 in real time
• If you need MP3 immediately during the session, you can receive raw audio (e.g., via Track Egress WebSocket / raw PCM stream), encode it to MP3 on your server in real time, and upload to S3. This is more complex but possible if low latency MP3 is required.
Practical FFmpeg example
• Convert OGG (Opus) to MP3:
◦ ffmpeg -i input.ogg -vn -acodec libmp3lame -ar 44100 -ac 2 -b:a 128k output.mp3
Automation outline (S3 + Lambda)
1. Configure egress to upload recordings to an S3 bucket.
2. Add an S3 ObjectCreated trigger to invoke a Lambda.
3. Lambda:
◦ Downloads the file.
◦ Runs FFmpeg (use a Lambda layer or run in a container) to transcode to MP3.
◦ Uploads MP3 to destination bucket/key and optionally deletes the original.
Questions to tailor the steps for you
• Do you want the recording per-participant or a mixed room audio file?
• Do you prefer conversion on-demand (manual/server) or fully automated (Lambda on S3 events)?
• Are you comfortable running FFmpeg in Lambda, or would you prefer a separate EC2/ECS service to do the conversion?
If you tell me which egress type you want (track vs room/composite) and whether you want automated conversion in AWS, I’ll provide a concrete example request body for starting egress and a sample Lambda/FFmpeg implementation.
Sources: Universal Egress | LiveKit | server-sdk-js | livekit/livekit_composite | DeepWiki, with interactive elementsabundant-father-33863
04/01/2026, 12:50 PMtall-airline-16756
04/01/2026, 12:51 PMpackage main
import (
"context"
"log"
"time"
"github.com/livekit/protocol/livekit"
"github.com/livekit/egress-sdk-go/egress"
)
func main() {
// Initialize the egress client (fill with your values)
egressAPIKey := "YOUR_EGRESS_API_KEY"
egressAPISecret := "YOUR_EGRESS_API_SECRET"
egressURL := "https://egress.livekit.example" // replace with your egress endpoint
client, err := egress.NewClient(egressURL, egressAPIKey, egressAPISecret)
if err != nil {
log.Fatalf("failed to create egress client: %v", err)
}
// Room and output target
roomName := "my-room"
outputFile := "mixed_audio.mp4" // container supporting stereo audio
bucket := "your-bucket-name"
region := "us-west-2"
accessKey := "AWS_ACCESS_KEY"
secret := "AWS_SECRET_KEY"
// Composite layout with audio mapping:
// - We request stereo output (2 channels).
// - Left channel will contain the customer's audio, right channel the AI agent.
// The layout JSON below is illustrative — adjust participant sources/track names to match your room.
layout := &livekit.RoomLayout{
Base: &livekit.Layout{
Width: 1920,
Height: 1080,
// Request stereo audio; LiveKit will mix according to audio mapping below.
Audio: &livekit.LayoutAudio{
// set to stereo (2 channels). If the SDK exposes channel count directly, set it; otherwise stereo is default for composite.
},
},
// Add regions/layers specifying which participant maps to which audio channel.
// Note: exact field names for channel mapping may vary; ensure you map participant audio tracks to left/right in your egress layout.
Layers: []*livekit.LayoutLayer{
{
Name: "customer_audio",
// Source could be participant identity or track name; use what identifies the customer's track.
Source: &livekit.LayoutLayer_SourceParticipant{
SourceParticipant: &livekit.LayoutLayer_Participant{
Identity: "customer-identity",
},
},
// For audio-only layers you can set position/size to zero or ignore visual parameters.
},
{
Name: "agent_audio",
Source: &livekit.LayoutLayer_SourceParticipant{
SourceParticipant: &livekit.LayoutLayer_Participant{
Identity: "ai-agent-identity",
},
},
},
},
}
// Build RoomCompositeEgressRequest
req := &livekit.RoomCompositeEgressRequest{
RoomName: roomName,
// Specify output formats & S3 upload config
Output: &livekit.EncodedFileOutput{
File: &livekit.EncodedFileOutput_File{
File: &livekit.EncodedFileOutput_File_S3{
S3: &livekit.S3Upload{
AccessKey: accessKey,
Secret: secret,
Bucket: bucket,
Region: region,
Key: outputFile,
},
},
},
},
// Set the desired file format; mp4 is used here to carry stereo audio.
// If the SDK requires explicit format field, set it to "mp4" or another supported container.
Layout: layout,
// Optionally set audio bitrate/sample rate if the API supports it
Audio: &livekit.RoomCompositeEgressRequest_AudioEncodingOptions{
// Example fields; exact names may vary in SDK:
Codec: livekit.AudioCodec_AAC, // choose a codec supported by the container
Bitrate: 128000,
SampleRateHz: 44100,
Channels: 2,
},
// Set a timeout or other request-level options
}
// Start the egress
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
res, err := client.StartRoomCompositeEgress(ctx, req)
if err != nil {
log.Fatalf("failed to start room composite egress: %v", err)
}
log.Printf("egress started: id=%s, file=%s", res.EgressId, outputFile)
}
Important implementation details and next steps
• Replace all placeholder values: egress credentials, egress endpoint, room name, participant identities, and S3 credentials.
• Confirm the exact layout and channel-mapping fields in your LiveKit egress SDK version. The code above shows the structure and intent — you may need to adapt field names to your SDK release.
• If the resulting file isn’t MP3, run FFmpeg to extract/convert to MP3:
◦ ffmpeg -i mixed_audio.mp4 -vn -ac 2 -ar 44100 -b:a 128k output.mp3
• If you want this fully automated, set an S3 ObjectCreated trigger that runs a Lambda (or container) to transcode to MP3 and store the final file.
If you’d like, I can:
• Produce a ready-to-run egress request payload matching the exact LiveKit SDK version you use (tell me which Go egress SDK version you have).
• Provide a sample AWS Lambda (or container) that runs FFmpeg to convert the uploaded file to MP3 automatically., with interactive elements