What is the proper URL format to use custom templa...
# ask-ai
q
What is the proper URL format to use custom templates with LiveKit egress compositing? Can I use query parameters or is there a different way to pass data?
t
Thanks for reaching out, Ari. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to use custom templates with LiveKit egress compositing, all you need to do is set the
custom_base_url
parameter in the
StartRoomCompositeEgress()
API. LiveKit will then automatically add these handy query parameters to your base URL: • `url`: The LiveKit WebSocket URL to connect to the room • `token`: The access token for authentication • `layout`: The layout parameter you pass to the template For example, it might look like this:
Copy code
<YOUR_WEB_SERVER_URL>?url=wss%3A%2F%2F<LIVEKIT_INSTANCE>&token=<RECORDER_TOKEN>&layout=grid
Feel free to add your own custom query parameters to the
custom_base_url
too, if you want to send extra info, like this:
Copy code
<YOUR_TEMPLATE_URL>/?yourparam=value
These custom parameters will stay intact along with the LiveKit parameters. When you’re working in your template, you can easily grab these values using JavaScript’s URL parsing methods. Hope this helps you get everything set up smoothly! Sources: Egress API | LiveKit Docs | Custom recording templates | LiveKit Docs | README.md | packages/livekit-server-sdk/src/EgressClient.ts
q
Thanks! Do I need the roomRecord permission in the token anywhere for custom templates to work properly?
t
Hey! Just a quick heads-up: the
roomRecord
permission needs to be included in your token for all LiveKit egress operations, even if you're using custom templates. This permission is essential to make sure the egress service works smoothly, no matter which template you choose. So, double-check that your token has this permission to keep everything running without a hitch! Sources: Egress API | LiveKit Docs | Universal Egress | Authentication | LiveKit Docs | livekit-api/livekit/api/egress_service.py | packages/livekit-server-sdk/src/EgressClient.ts
q
Awesome, thank you! Here are some questions: 1. Viewport/Canvas Sizing: “When using custom templates for room composite egress, should the template use fixed pixel dimensions (like 1920x1080px) or viewport units (100vw/100vh) for the main container? We’re seeing a blue debug border cut off at the edges.” 2. Egress Dimensions: “We’re passing width: 1920, height: 1080 to the egress options, but our custom template’s container seems to be scaled incorrectly. How does LiveKit’s browser rendering viewport relate to the specified egress dimensions?” 3. Template Container Best Practices: “What’s the recommended CSS approach for the root container of a custom composite template? Should it fill the browser viewport or match the egress dimensions exactly?”
t
Here are some answers to your questions about custom templates for LiveKit room composite egress — I hope this helps clarify things! 1. Viewport/Canvas Sizing: LiveKit uses a headless Chromium instance to render the composited view. For the main container, it’s best to stick with fixed pixel dimensions (like 1920x1080px) instead of viewport units (such as 100vw/100vh). This way, you’ll get consistent rendering and avoid issues like the blue debug border getting cut off. Just a heads-up, Chrome has a minimum browser width of 500px, so keep that in mind when designing your templates. 2. Egress Dimensions: The dimensions you pass in (for example, width: 1920, height: 1080) directly control the rendering viewport in Chromium. If your custom template’s container looks scaled the wrong way, double-check that the CSS in your template exactly matches those egress dimensions. Since the rendering viewport resizes to the resolution you request, any mismatch in CSS can cause scaling hiccups. 3. Template Container Best Practices: For the root container of your custom composite template, it’s a good idea to match the egress dimensions exactly (like 1920x1080px) using fixed pixel sizes. You can also use responsive design principles to make sure your template works well across different aspect ratios. Just try to avoid relying only on viewport units, as they might not sync up perfectly with the egress rendering process. Following these tips should help you get high-quality, consistent recordings. If you want me to explain anything further or need a hand with anything else, just let me know — I’m happy to help! Sources: livekit-api/src/services/egress.rs | livekit-protocol/livekit/protocol/egress.py | Composite and web recordings | LiveKit Docs | Universal Egress | Custom Recording Template | LiveKit Docs
q
Is there any way we can debug that chromium instance directly? we’ve been resorting to putting debug elements in HTML elements in the composite view.
t
Hey there! Just a quick heads-up: direct debugging of the Chromium instance used in LiveKit egress compositing (like attaching DevTools) isn’t supported right now. But no worries—you can still enable Chrome logging to capture console output and events, which can be super helpful for debugging. Just use the
DebugConfig.EnableChromeLogging
option in your configuration file, and it’ll log all Chrome console events to a file at
/tmp/chrome.log
inside the container. Also, feel free to use debug elements in your HTML template like you mentioned—that’s a great way to get more insight into what’s happening during rendering. If you want, I’m here to help you set up Chrome logging or chat about other debugging tips. Just let me know! Sources: pkg/config/base.go | Chrome Developer Extension | livekit/livekit_composite | DeepWiki | Knowledge Management System | livekit/livekit_composite | DeepWiki
q
We added some debug and it looks like LiveKit’s Viewport is 1279x719 instead of 1920x1080 like we expected. Any idea what could be causing that?
t
Hey there! If you’re seeing a LiveKit Chromium viewport resolution of 1279x719 instead of the expected 1920x1080, it might be because the egress configuration isn’t explicitly set to the resolution you want. Here are a couple of things to double-check: • Try using the
H264_1080P_30
or
H264_1080P_60
preset in your egress request—these presets clearly specify a resolution of 1920x1080. • If you’re using advanced encoding options, make sure you’ve explicitly set
width: 1920
and
height: 1080
in your configuration. Also, take a peek at whether dynamic layout or URL parameters in your custom template might be affecting the resolution. If you want, I’m here to help you walk through these settings—just let me know! Sources: protobufs/livekit_egress.proto | pkg/pipeline/source/web.go | livekit-protocol/livekit/protocol/egress.py
q
Thanks! Here’s what my AI said: ⏺️ I can see that we ARE setting width: 1920, height: 1080 in the egress options. The AI suggested using presets like H264_1080P_30 instead. Let me check what the actual egress creation call looks like: ⏺️ Search(pattern: “startRoomCompositeEgress|egressClient\.startRoomCompositeEgress”, path: “../costream/backend/src/services/livekit.js”, output_mode: “content”) ⎿ Found 107 lines (ctrl+r to expand) ⏺️ I found the issue! Our startRoomCompositeEgress calls are passing the width and height in the options object, but according to the LiveKit AI, we should be using encoding presets instead. Let me fix this by using the proper H264 preset: Update(~/Developer/costream/backend/src/services/livekit.js) ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Edit file │ │ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ ../costream/backend/src/services/livekit.js │ │ │ │ │ │ │ │ 602 egressOptions = { │ │ │ │ 603 layout: ‘custom’, │ │ │ │ 604 customBaseUrl: customTemplateUrl, │ │ │ │ 605 - width: 1920, │ │ │ │ 606 - height: 1080, │ │ │ │ 605 + preset: ‘H264_1080P_30’, // Use preset instead of width/height │ │ │ │ 606 audioOnly: false, │ │ │ │ 607 videoOnly: false │ │ │ │ 608 }; │ │ │ │ ... │ │ │ │ 611 console.log(‘📋 Using default grid layout’); │ │ │ │ 612 egressOptions = { │ │ │ │ 613 layout: ‘grid’, │ │ │ │ 614 - width: 1920, │ │ │ │ 615 - height: 1080, │ │ │ │ 614 + preset: ‘H264_1080P_30’, // Use preset instead of width/height │ │ │ │ 615 audioOnly: false, │ │ │ │ 616 videoOnly: false │ │ │ │ 617 };
t
Hey, it seems like you’ve nailed the issue by switching to the
H264_1080P_30
preset instead of setting the width and height manually. This should fix the viewport mismatch and make sure your egress compositing comes out at the right 1920x1080 resolution. If you run into any other hiccups or need a hand with anything else, just give me a shout—I’m here to help!
q
what is the appropriate preset for 9:16?
t
Here are the encoding presets that work best for a 9:16 aspect ratio in LiveKit egress compositing: • `PORTRAIT_H264_720P_30`: 720x1280 resolution, 30fps • `PORTRAIT_H264_720P_60`: 720x1280 resolution, 60fps • `PORTRAIT_H264_1080P_30`: 1080x1920 resolution, 30fps • `PORTRAIT_H264_1080P_60`: 1080x1920 resolution, 60fps Just pick the preset that fits the resolution and frame rate you're aiming for. And if you want a hand setting these up, I’m here to help! Sources: protobufs/livekit_egress.proto | pkg/config/pipeline.go | Egress examples | LiveKit Docs
q
an you ask the LiveKit AI this question: “We’re setting preset: ‘H264_1080P_30’ in our room composite egress options, but the Chromium viewport is still 1279×719 instead of 1920×1080. We’re streaming to Twitch via RTMP. Could the RTMP StreamOutput configuration be overriding our egress resolution settings? Do we need to specify encoding parameters in the StreamOutput object as well?”
t
Just a quick heads-up: the RTMP StreamOutput configuration doesn’t actually override the egress resolution settings in LiveKit. The encoding details, like resolution, are set up at the egress request level using either: • A preset option (for example,
H264_1080P_30
) • Advanced encoding options like
width
,
height
, and
bitrate
The StreamOutput object itself only has fields for
protocol
and
urls
, and doesn’t include any encoding parameters. If things still look off with the resolution, it might be a good idea to double-check your egress request setup to make sure the preset or encoding options are set correctly. Feel free to reach out if you want a hand troubleshooting this—I’m here to help! Sources: livekit/livekit_egress.pb.go | Egress output types | LiveKit Docs
q
“Our egress request logs show preset: ‘H264_1080P_30’ is being set correctly, and the egress starts successfully (status 0), but the Chromium viewport in our custom template is still showing 1279×719 instead of 1920×1080. We’re using LiveKit server SDK v2.13.1. Could there be: 1. A difference between egress presets and template rendering viewport? 2. Some LiveKit server configuration that’s overriding preset resolutions? 3. An issue with how custom templates receive viewport dimensions vs built-in layouts? Our template debug shows: Viewport: 1279×719, Container: 1920×1080, Body: 1259×699”
t
Hey there! It looks like the Chromium viewport is showing 1279x719 instead of the expected 1920x1080, even though you’re using the
H264_1080P_30
preset. This can happen for a few reasons: 1. Template Viewport Size: The actual rendering resolution depends on the browser viewport size set during compositing. While the preset controls the encoder settings for the final output, if your custom template’s container or video element isn’t explicitly set to 1920x1080, the viewport might default to a smaller size. 2. Custom Template Configuration: Make sure your custom template uses CSS or JavaScript to set the display container or video element to fill a 1920x1080 viewport. For example, setting the
width
and
height
of the container to 100% of the browser window can help. Also, double-check that your egress request is pointing to this updated template via
customBaseUrl
. 3. Headless Chromium Behavior: Sometimes, Chrome’s headless browser can slightly tweak the resolution (like 1279x719) due to encoding alignment or metadata rounding. But if your template is correctly set up for 1920x1080, this shouldn’t happen. To fix this, take another look at your custom template’s CSS to make sure it explicitly supports the resolution you want. And if you want, I’m here to help you debug or tweak the template further—just let me know!
q
This is how Claude responded to that: Excellent! This confirms exactly what we suspected. The issue is that the template viewport size is independent of the encoding preset. The H264_1080P_30 preset controls the final encoded output (what Twitch receives), but the Chromium viewport that renders our template is still using a default size. We need to ensure our template explicitly uses the full 1920×1080 viewport. Let me fix this: ⏺️ Update(~/Developer/costream/custom-composite-template/src/App.tsx) ⎿ Updated ../costream/custom-composite-template/src/App.tsx with 8 additions and 4 removals 124 125 return ( 126 <div style={{ 127 - width: ‘1920px’, 128 - height: ‘1080px’, 127 + width: ‘100vw’, 128 + height: ‘100vh’, 129 + minWidth: ‘1920px’, 130 + minHeight: ‘1080px’, 131 position: ‘absolute’, 132 top: 0, 133 left: 0, ... 168 169 return ( 170 <div style={{ 171 - width: ‘1920px’, 172 - height: ‘1080px’, 171 + width: ‘100vw’, 172 + height: ‘100vh’, 173 + minWidth: ‘1920px’, 174 + minHeight: ‘1080px’, 175 position: ‘absolute’, 176 top: 0, 177 left: 0, ⏺️ Update(~/Developer/costream/custom-composite-template/src/CustomLayout.tsx) ⎿ Updated ../costream/custom-composite-template/src/CustomLayout.tsx with 5 additions and 3 removals 43 44 const { canvas, elements, settings } = layoutData; 45 46 - // Container style to exactly match egress dimensions (per LiveKit AI advice) 46 + // Container style to fill the entire Chromium viewport (per LiveKit AI advice) 47 const containerStyle: CSSProperties = { 48 - width:
${canvas.width}px
, 49 - height:
${canvas.height}px
, 48 + width: ‘100vw’, 49 + height: ‘100vh’, 50 + minWidth:
${canvas.width}px
, 51 + minHeight:
${canvas.height}px
, 52 backgroundColor: settings.backgroundColor, 53 position: ‘absolute’, 54 top: 0, ⏺️ Now the template will: 1. Fill the entire Chromium viewport with 100vw/100vh 2. Ensure minimum 1920×1080 dimensions with minWidth/minHeight 3. The preset handles encoding the final output at 1920×1080
t
Hey, it looks like you’ve made the right changes to make sure your custom template fills the whole Chromium viewport while keeping that minimum resolution of 1920×1080. Using the
H264_1080P_30
preset along with this should help fix the viewport mismatch and get your final output encoded just right. If you run into any other issues or need a hand with anything else, just let me know—I’m here to help!
q
These changes didnt seem to make an impact which seems odd?
t
Hey there! If you noticed that changing your custom template's viewport settings (like
100vw/100vh
with
minWidth/minHeight
) didn’t seem to affect the Chromium viewport, it’s probably because the LiveKit egress service manages the browser resolution separately from your page’s CSS. Basically, the resolution you set in the egress request (whether through a preset or advanced options) will override the CSS viewport units. Make sure the resolution in your egress request matches what you want (for example, 1920x1080 if you’re using
H264_1080P_30
). Also, double-check that your custom template’s layout fits that resolution so everything looks just right. If you want, I’m happy to help you troubleshoot this further—just let me know! Sources: Egress examples | LiveKit Docs | RoomComposite Egress | LiveKit Docs
q
You’re absolutely right to question that! The LiveKit AI specifically said to avoid viewport units in their earlier advice. I made an error by going back to vw/vh units. The real issue is that the Chromium viewport itself is being set to 1279×719 by LiveKit, not that our template needs to fill a larger viewport. We need to ask LiveKit to configure the Chromium browser window size to 1920×1080, not just the encoding preset. Can you ask the LiveKit AI this: “Our custom template is correctly configured, but LiveKit’s Chromium browser is launching with a viewport size of 1279×719 instead of 1920×1080. The H264_1080P_30 preset controls the final encoding, but how do we control the actual Chromium browser window/viewport size that renders our template? Is there a way to specify the browser dimensions in the egress request, or does the preset also control the Chromium viewport size? We need the browser to render at 1920×1080 before encoding.” The issue seems to be that LiveKit is launching Chromium with the wrong window dimensions, regardless of our template CSS. We need to control the browser launch parameters, not just our HTML/CSS.
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!
q
“We’re using preset: ‘H264_1080P_30’ in our room composite egress request with LiveKit server SDK v2.13.1, but the Chromium viewport is still 1279×719 instead of 1920×1080. Here’s our exact egress options: { “layout”: “custom”, “customBaseUrl”: “https://...“, “preset”: “H264_1080P_30", “audioOnly”: false, “videoOnly”: false } 1. Is H264_1080P_30 the correct preset name for 1920×1080? 2. Are there any known issues with preset resolution handling in SDK v2.13.1? 3. Should we use advanced encoding options instead of preset?”
Is there any way to view egress logs?