colossal-lock-10836
08/30/2025, 11:39 AMtall-airline-16756
08/30/2025, 11:39 AMtall-airline-16756
08/30/2025, 11:41 AM-v flag to mount a local directory, like -v ~/livekit-egress:/out/. Just double-check that the egress service has write permissions for that directory.
2. Next, use the Python SDK’s RoomCompositeEgressRequest class to set up your egress job. You’ll want to set the file_outputs parameter to an EncodedFileOutput object, pointing the filepath to the mounted directory with your chosen filename, for example, /out/recording.mp4.
3. Don’t forget to specify the room_name for the room you want to record, and feel free to customize other settings like layout, preset, or audio_only to fit your needs.
4. Finally, use the LiveKitAPI instance to kick off the egress job with your configuration.
Here’s a little Python snippet to get you started:
from livekit import api
async def start_local_recording(room_name: str, filepath: str):
# Set up the egress request for saving locally
req = api.RoomCompositeEgressRequest(
room_name=room_name,
audio_only=True,
file_outputs=[api.EncodedFileOutput(
file_type=api.EncodedFileType.MP4,
filepath=filepath,
)],
)
# Create your LiveKit API client
lkapi = api.LiveKitAPI(
url="your_livekit_url", # for example, "wss://your-domain.com"
api_key="your_api_key",
api_secret="your_api_secret"
)
# Start the recording job
res = await lkapi.egress.start_room_composite_egress(req)
# Don't forget to close the client when done
await lkapi.aclose()
return res
So, when you call start_local_recording("my-room", "/out/my-recording.mp4"), it’ll start recording that room and save the file right to your local file system at /out/my-recording.mp4 — just make sure /out matches the mounted volume in your Docker container. The recording will automatically stop once everyone leaves the room. Pretty neat, right?
Sources: README.md | Egress & Storage | livekit/livekit_composite | DeepWiki | livekit-protocol/livekit/protocol/egress.py | Session recording and transcripts | LiveKit Docs