can I record the video stream with livekit-api pyt...
# ask-ai
a
can I record the video stream with livekit-api python package?
t
Thanks for reaching out, Anne. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Yes, you can record video streams using the LiveKit API Python package through LiveKit's Egress feature. The Python API provides several recording options: • Room composite recording - Records all participants and interactions in a room • Participant recording - Records a specific participant • Track recording - Records individual audio or video tracks • Track composite recording - Records composite audio and video tracks Here is an example of how to set up a basic recording:
Copy code
from livekit import api

# Set up recording request
req = api.RoomCompositeEgressRequest(
    room_name="my-room",
    layout="speaker",
    preset=api.EncodingOptionsPreset.H264_720P_30,
    audio_only=False,  # Set to True for audio-only recording
    # Configure output destination (cloud storage required)
)

# Start recording
lkapi = api.LiveKitAPI()
res = await lkapi.egress.start_room_composite_egress(req)
Note: Recording requires access to a cloud storage provider to upload the recording files. Supported providers include: • Amazon S3 and S3-compatible storage • Google Cloud Storage • Azure Blob Storage Available methods for recording include: •
start_room_composite_egress()
- Composite recording of a room •
start_participant_egress()
- Recording of a participant •
start_track_egress()
- Recording of a single track •
start_track_composite_egress()
- Composite recording with audio and video tracks •
stop_egress()
- Stop an active recording •
list_egress()
- List active and recent recordings Let me know if you need further details on any specific recording method or setup! Sources: Session recording and transcripts | LiveKit Docs | livekit-api/livekit/api/egress_service.py | Recording agent sessions | LiveKit Docs
a
this seems to use the livekit package which is very heavy and not the livekit-api package. Can I do it with the livekit-api package?
t
Absolutely, you can record video streams using the livekit-api Python package! This package connects you to LiveKit's Egress service, which gives you some great flexible options for recording audio and/or video streams. Here’s a quick rundown of the recording methods available: • Room Composite Recording: Captures everything happening in a LiveKit room — all participants and interactions — using
start_room_composite_egress()
• Participant Recording: Focuses on recording a specific participant with
start_participant_egress()
• Track Composite Recording: Records composite audio and video tracks via
start_track_composite_egress()
• Individual Track Recording: Records just a single track using
start_track_egress()
Here’s a simple example of setting up video recording with the livekit-api package:
Copy code
from livekit import api

# Create LiveKit API client
lkapi = api.LiveKitAPI()

# Set up room composite recording
req = api.RoomCompositeEgressRequest(
    room_name="my-room",
    layout="speaker",
    preset=api.EncodingOptionsPreset.H264_720P_30,
    audio_only=False,  # Switch to True if you want audio-only recording
    # Don’t forget to configure your output destination (cloud storage needed)
)

# Start the recording
res = await lkapi.egress.start_room_composite_egress(req)
Just a couple of things to keep in mind: • You’ll need access to a cloud storage provider like Amazon S3, Google Cloud Storage, or Azure Blob Storage to save your recordings • Make sure you have the right authentication credentials set up for your storage provider The recording kicks off as soon as participants join the room, capturing all the audio and video shared, and it wraps up automatically when everyone leaves. Pretty handy, right? Sources: livekit-api/livekit/api/egress_service.py | Session recording and transcripts | LiveKit Docs | Recording agent sessions | LiveKit Docs
a
so I should set this up each time I create a room, correct?
t
No worries, you don’t have to set up recording every time you create a room. LiveKit offers a handy autoegress feature that automatically records rooms right when they’re created. When you create a room, you can set up the
egress
field to either record the whole room as a composite or capture each published track separately. This setup only needs to be done once during room creation, and then recording kicks off automatically. Here’s a simple example showing how to configure auto egress to record all tracks to S3 when creating a room:
Copy code
{
  "name": "my-room",
  "egress": {
    "tracks": {
      "filepath": "bucket-path/{room_name}-{publisher_identity}-{time}",
      "s3": {
        "access_key": "",
        "secret": "",
        "bucket": "mybucket",
        "region": ""
      }
    }
  }
}
Another option: If you’d rather have more control, you can always start recording manually after the room is created using the egress API. For example, you might start a room composite recorder when participants join the room. Using auto egress makes things easier by taking away the hassle of setting up recording every time, since the configuration happens automatically during room creation.
a
can you point me to the docs for that auto egress?
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!
a
this worked:
Copy code
{
  "name": "my-room",
  "egress": {
    "tracks": {
      "filepath": "bucket-path/{room_name}-{publisher_identity}-{time}",
      "s3": {
        "access_key": "",
        "secret": "",
        "bucket": "mybucket",
        "region": ""
      }
    }
  }
}
But it saved all tracks separately