participant egress example which creating room
# ask-ai
l
participant egress example which creating room
t
Thanks for reaching out, Piyush. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To create a participant egress for audio using the LiveKit Egress API, follow these steps: 1. Use the
ParticipantEgressRequest
struct to specify the room name, participant identity, and other options like encoding and file outputs. 2. Call the
StartParticipantEgress
method on the Egress client with your request. This will return an
EgressInfo
object containing details about the started egress. Here is an example in Python:
Copy code
from livekit.protocol.egress import (
    ParticipantEgressRequest,
    EncodedFileOutput,
    S3Upload,
    EncodingOptionsPreset,
)
from livekit.api import LiveKitAPI

# Initialize the LiveKit API client
lk = LiveKitAPI(api_key="your_api_key", api_secret="your_api_secret")

# Create an S3 upload configuration
s3_config = S3Upload(
    access_key="your_access_key",
    secret="your_secret_key",
    region="your_bucket_region",
    bucket="your_bucket_name",
)

# Create the file output configuration for MP4
file_output = EncodedFileOutput(
    filepath="participant-recording.mp4",
    file_type=EncodedFileType.MP4,
    s3=s3_config,
)

# Create the ParticipantEgressRequest
request = ParticipantEgressRequest(
    room_name="your_room_name",
    identity="participant_identity",
    screen_share=False,
    options=EncodingOptionsPreset.H264_720P_30,
    file_outputs=[file_output],
)

# Start the participant egress
egress_info = lk.egress.start_participant_egress(request)

print(f"Egress Started: {egress_info}")
This example demonstrates how to configure and start a participant egress for audio recording. Let me know if you need further assistance! Sources: Recording participants | LiveKit Docs | protobufs/livekit_egress.proto
l
while creating a room
t
Hey! Just wanted to check in and understand a bit better—how does creating a room tie into your request about participant egress? Are you hoping to set up participant egress right after the room is created, or is there something else you're thinking of? I'm here to help!
l
while creating a room i can steup the participant egress using auto egress right?
t
Absolutely! You can set up participant egress automatically right when you create a room by using auto egress. Just include the egress configuration in the
CreateRoomRequest
. Specifically, the
RoomEgress
field is where you set up automatic participant egress. Here’s a quick example of how your request might look:
Copy code
{
  "name": "my-room",
  "egress": {
    "participant": {
      "fileOutputs": [...],
      "segmentOutputs": [...],
      "options": {
        // participant egress options
      }
    }
  }
}
Once you’ve got auto participant egress set up, the system will automatically start participant egress as soon as participants join the room—so you don’t have to worry about setting it up manually after creating the room. If you want, I’m here to help with any more details or questions you have about the setup! Sources: livekit/livekit_room.pb.go | cmd/lk/egress.go | Auto Egress | LiveKit Docs | pkg/rtc/egress.go
l
give a detailed example
t
Here’s a detailed example to help you set up auto participant egress while creating a room: 1. Create a JSON Configuration File Start by creating a JSON file for your
AutoParticipantEgress
settings. Here’s an example:
Copy code
{
  "filepath": "<s3://my-bucket/{room_name}-{participant_identity}-{timestamp}>",
  "s3": {
    "access_key": "YOUR_AWS_ACCESS_KEY",
    "secret": "YOUR_AWS_SECRET_KEY",
    "bucket": "my-bucket",
    "region": "us-east-1"
  }
}
- The
filepath
is where your recorded files will be saved. - The
s3
section holds your AWS credentials and configuration details. 2. Use the Configuration File When Creating a Room When you create a room, just point to this JSON file using the
--participant-egress-file
flag. Here’s the CLI command you’d use:
Copy code
lk room create my-room --participant-egress-file examples/auto-participant-egress.json
- Make sure to replace
auto-participant-egress.json
with the path to your actual JSON file. - This command will create a room with auto participant egress turned on. 3. Programmatic Example (Go) If you’re working with the LiveKit Go SDK, here’s how you can set up auto participant egress programmatically:
Copy code
import (
    "context"
    "<http://github.com/livekit/protocol/livekit|github.com/livekit/protocol/livekit>"
    lksdk "<http://github.com/livekit/server-sdk-go/v2|github.com/livekit/server-sdk-go/v2>"
)

func createRoomWithEgress() error {
    ctx := context.Background()
    client := lksdk.NewRoomServiceClient("your-server-url") 

    egressConfig := &livekit.AutoParticipantEgress{
        FileOutputs: []*livekit.DirectFileOutput{{
            Filepath: "<s3://my-bucket/{room_name}-{participant_identity}-{timestamp}>",
            Output: &livekit.DirectFileOutput_S3{
                S3: &livekit.S3Output{
                    Bucket:    "my-bucket",
                    AccessKey: "YOUR_AWS_ACCESS_KEY",
                    Secret:    "YOUR_AWS_SECRET_KEY",
                    Region:    "us-east-1",
                },
            },
        }},
    }

    req := &livekit.CreateRoomRequest{
        Name: "my-room",
        Egress: &livekit.RoomEgress{
            Participant: egressConfig,
        },
    }

    _, err := client.CreateRoom(ctx, req)
    return err
}
This setup tells LiveKit to automatically record all participant sessions and save them right into your specified S3 bucket. If you have any questions or want me to walk you through more examples, just let me know—I’m here to help! Sources: livekit/livekit_room.pb.go | cmd/lk/room.go
l
give js example
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
l
how to start room composite egress request?