I’m currently recording the user’s camera and micr...
# ask-ai
w
I’m currently recording the user’s camera and microphone using Engress, but I’d like to either include screen recording as well or create a custom layout around the video recording.
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you include screen recording or create a custom layout for video recording! You have two great options to choose from: • Screen Recording: You can use
startParticipantEgress
with the
screen_share
parameter set to
true
. This lets you capture a participant's screen and audio, which is perfect for things like lecture recordings or agent assistance. • Custom Layout: Another option is to use
StartRoomCompositeEgress
along with a custom web app. By hosting your own HTML/React app and setting its URL as the
customBaseUrl
, you can create a fully personalized recording layout—whether that’s grids, speaker focus, or even branded overlays. If you’d like, I can walk you through the detailed steps for either option. Just let me know, and I’ll be here to guide you! Sources: lib/livekit/egress_service_client.rb | livekit-api/livekit/api/egress_service.py | livekit-protocol/src/livekit.rs | Custom recording templates | LiveKit Docs | template-sdk/src/index.ts
w
Copy code
# Set up recording request
        req = api.RoomCompositeEgressRequest(
            room_name=ctx.room.name,
            audio_only=False,  # Record both audio and video
            file_outputs=[api.EncodedFileOutput(
                file_type=api.EncodedFileType.MP4,  # Use MP4 for video
                filepath=filename.replace('.ogg', '.mp4'),  # Change extension to .mp4
                s3=api.S3Upload(
                    bucket=s3_bucket,
                    region=s3_region,
                    access_key=s3_access_key,
                    secret=s3_secret_key,
                ),
            )],
        )
        
        # Start recording with proper LiveKit API configuration
        lkapi = api.LiveKitAPI(
            url=livekit_url,
            api_key=livekit_api_key,
            api_secret=livekit_api_secret
        )
res = await lkapi.egress.start_room_composite_egress(req)
This is my code, you can tell me where i need to pass param for screen share
t
Thanks for sharing your code! Your current setup with
RoomCompositeEgressRequest
already includes screen sharing by default, as long as participants are actively sharing their screens during the session. So, no extra parameters are needed to get screen share working here. If you’d like to record just the screen share from a specific participant, you can switch to using
ParticipantEgressRequest
and set the
screenShare
parameter to
true
. That should do the trick! Feel free to reach out if you want me to walk you through any part of this or help tweak your code further. I’m here to help! Sources: Universal Egress | Composite and web recordings | LiveKit Docs | RoomComposite Egress | LiveKit Docs | packages/livekit-server-sdk/src/EgressClient.ts
w
But we're asking user to share the screen, difference is that we build that on our own hence is there any way to pass screen share stream to livekit and ask livekit to record it?
t
To pass a custom screen share stream to LiveKit for recording, you’ll want to publish the screen share track from your client application and set up LiveKit to record it. Here’s a simple guide to help you through the process: 1. Publish the Screen Share Track: Depending on your platform, you can use specific SDK methods to create and publish the screen share track: ◦ Web: Use
createScreenTracks()
to capture the screen, then publish it with
localParticipant.publishVideoTrack()
. ◦ iOS/macOS: Use
createMacOSScreenShareTrack()
or
createBroadcastScreenCapturerTrack()
to create and publish your track. ◦ Android: Utilize
MediaProjectionManager
along with
setScreenShareEnabled()
to enable screen sharing. 1. Enable Recording: To record just the screen share, use
ParticipantEgressRequest
with
screen_share=true
. If you want to include it in the full room recording, go with
RoomCompositeEgressRequest
. If you’d like, I’d be happy to provide specific code examples for your platform or help you with any other questions you might have. Just let me know! Sources: Docs/ios-screen-sharing.md | Screen sharing | LiveKit Docs | README.md | Recording participants | LiveKit Docs | Custom recording templates | LiveKit Docs
w
Can you show detailed example for web?
t
Here’s a detailed example for publishing a screen share track on the web using LiveKit and recording it: Publishing Screen Share Track To get started, you can use the
createScreenTracks
method from the LiveKit JS SDK. This lets you capture the screen and, if you like, include audio too:
Copy code
try {
  const screenTracks = await createScreenTracks({
    audio: true, // Enable audio sharing if supported
    resolution: '1080p', // Specify resolution
  });

  // Publish the video track
  await room.localParticipant.publishTrack(screenTracks[0]);

  // If audio is included, publish the audio track
  if (screenTracks.length > 1) {
    await room.localParticipant.publishTrack(screenTracks[1]);
  }
} catch (error) {
  console.error('Error publishing screen share:', error);
}
Recording the Screen Share 1. Enable Screen Share in Egress Request: When you start a recording, just set
screen_share=true
in the egress request parameters. This ensures the screen share and its audio are captured. 2. Start Recording: The Egress service will take care of recording the screen share track as soon as it’s published. It also manages mute states and will stop recording when the participant leaves the room. If you have any questions or need a hand with the recording setup or more examples, please don’t hesitate to ask—I’m here to help! Sources: Screen sharing | LiveKit Docs | Recording participants | LiveKit Docs
w
But how can i pass custom screenshare stream here??
t
I'd love to help you pass a custom screen share stream to LiveKit! You can definitely use an HTML canvas or any other custom video source for this. Here’s a simple way to do it: 1. Capture the Custom Stream: Start by using the
captureStream()
method to create a MediaStream from an HTML canvas or another source:
Copy code
const canvas = document.getElementById('myCanvas');
const mediaStream = canvas.captureStream(30); // 30 fps
2. Publish the Stream: Next, grab the video track from the MediaStream and publish it to LiveKit like this:
Copy code
const videoTrack = mediaStream.getVideoTracks()[0];
localParticipant.publishTrack(videoTrack, {
  name: "custom-screen-share",
  source: Track.Source.ScreenShare, // or Track.Source.Unknown
});
3. Record the Stream: To make sure your custom screen share is recorded, use Participant Egress with
screen_share=true
. This method lets you share all kinds of custom visuals, whether it’s animations, presentations, or anything else you want to show. If you have any questions or need a hand with any step, just let me know—I’m here to help! Sources: Recording participants | LiveKit Docs | Sources/LiveKit/Broadcast/BroadcastScreenCapturer.swift | Screen sharing | LiveKit Docs | src/room/participant/LocalParticipant.ts
w
It worked but the recording having both screen recording and user camera preview side by side, since screen recording showing user face as well, i don't want user camera preview, how can i hide it?
t
Thanks for reaching out! Could you please let me know if you're using a custom layout for the recording or the default layout that LiveKit provides? If it’s a custom layout, no worries—you can easily adjust it to remove the camera preview. Just let me know, and I’ll be happy to walk you through the next steps!
w
not using any custom layout, just simple engress setup, as shown here :-
Copy code
# Set up recording request
        req = api.RoomCompositeEgressRequest(
            room_name=ctx.room.name,
            audio_only=False,  # Record both audio and video
            file_outputs=[api.EncodedFileOutput(
                file_type=api.EncodedFileType.MP4,  # Use MP4 for video
                filepath=filename.replace('.ogg', '.mp4'),  # Change extension to .mp4
                s3=api.S3Upload(
                    bucket=s3_bucket,
                    region=s3_region,
                    access_key=s3_access_key,
                    secret=s3_secret_key,
                ),
            )],
        )
        
        # Start recording with proper LiveKit API configuration
        lkapi = api.LiveKitAPI(
            url=livekit_url,
            api_key=livekit_api_key,
            api_secret=livekit_api_secret
        )
res = await lkapi.egress.start_room_composite_egress(req)
t
I’m happy to help you exclude the user camera preview from the recording while using RoomCompositeEgress! You have two great options to achieve this: 1. Custom Template: You can create a custom recording template to control the layout and leave out specific tracks. Here’s how: ◦ Start by cloning the default LiveKit template from the LiveKit egress repository. ◦ Then, modify the layout logic in files like
Room.tsx
or
SpeakerLayout.tsx
to exclude the camera preview. ◦ Finally, deploy your customized template and set its URL using the
custom_base_url
parameter when you start the egress. 1. Alternative API Options: If custom templates aren’t your preference, you might want to try these: ◦ ParticipantEgress: This lets you record specific participants one by one, so you can simply leave out the participant whose camera preview you want to exclude. ◦ TrackCompositeEgress: This option allows you to record only the audio and video tracks you choose, giving you precise control over what’s included. If you’d like, I’d be more than happy to walk you through detailed steps for any of these approaches or answer any questions you have. Just let me know! Sources: packages/livekit-server-sdk/src/EgressClient.ts | livekit-protocol/livekit/protocol/egress.pyi | Custom recording templates | LiveKit Docs