abundant-magician-17307
07/28/2025, 1:21 AMtall-airline-16756
07/28/2025, 1:21 AMtall-airline-16756
07/28/2025, 1:22 AM@livekit/track-processors package with built-in virtual background support:
• BackgroundBlur(blurRadius) - Applies a blur effect to the background
• VirtualBackground(imagePath) - Replaces the background with a custom image
Basic Usage Example:
import { BackgroundBlur, VirtualBackground, supportsBackgroundProcessors } from '@livekit/track-processors';
if(!supportsBackgroundProcessors()) {
throw new Error("this browser does not support background processors")
}
const videoTrack = await createLocalVideoTrack();
const blur = BackgroundBlur(10);
await videoTrack.setProcessor(blur);
room.localParticipant.publishTrack(videoTrack);
// To disable
async function disableBackgroundBlur() {
await videoTrack.stopProcessor();
}
// Virtual background
const virtualBg = VirtualBackground('/path/to/image.jpg');
await videoTrack.setProcessor(virtualBg);
React Implementation Example:
import { BackgroundBlur, VirtualBackground } from '@livekit/track-processors';
import { isLocalTrack } from 'livekit-client';
export function CameraSettings() {
const { cameraTrack } = useLocalParticipant();
const [backgroundType, setBackgroundType] = React.useState<'none' | 'blur' | 'image'>('none');
React.useEffect(() => {
if (isLocalTrack(cameraTrack?.track)) {
if (backgroundType === 'blur') {
cameraTrack.track?.setProcessor(BackgroundBlur());
} else if (backgroundType === 'image' && virtualBackgroundImagePath) {
cameraTrack.track?.setProcessor(VirtualBackground(virtualBackgroundImagePath));
} else {
cameraTrack.track?.stopProcessor();
}
}
}, [cameraTrack, backgroundType, virtualBackgroundImagePath]);
}
Android Implementation:
LiveKit provides the VirtualBackgroundVideoProcessor for Android:
Installation:
Sources: lib/CameraSettings.tsx | livekit-android-track-processors/src/main/java/io/livekit/android/track/pro... | Development Tools | livekit/livekit_composite | DeepWiki | src/transformers/BackgroundTransformer.tsabundant-magician-17307
07/28/2025, 2:38 AMtall-airline-16756
07/28/2025, 2:40 AMoriginal preset in ScreenSharePresets that captures your screen exactly as it is, without any annoying resizing:
export const ScreenSharePresets = {
// ... other presets
// original resolution, without resizing
original: new VideoPreset(0, 0, 7_000_000, 30, 'medium'),
}
Cool, right? This preset grabs your screen's native resolution and gives you a generous 7 Mbps bitrate to handle those high-res details.
2. Specify a Custom 2K Resolution:
Want more control? No problem! You can easily define a custom 2K resolution (2560x1440) using `ScreenShareCaptureOptions`:
const screenShareOptions = {
resolution: {
width: 2560,
height: 1440,
frameRate: 30
}
};
3. Ensure Sufficient Bitrate:
Pro tip for 2K content: allocate 6-8 Mbps to keep things looking sharp. You can set this up in your encoding settings:
const publishOptions = {
screenShareEncoding: ScreenSharePresets.original.encoding
};
And just like that, you're all set to push stunning 2K screen sharing! Let me know if you need any more help along the way.
Sources: examples/demo/demo.ts | lib/src/types/video_parameters.dartabundant-magician-17307
07/28/2025, 2:52 AMtall-airline-16756
07/28/2025, 2:53 AMscreenShareEncoding to 1080p but you've got a super crisp 2K display, LiveKit's got a smart solution for you.
Resolution Scaling Process:
• First, LiveKit grabs your entire screen at its full, beautiful 2K resolution.
• Then, it gently scales things down to fit that 1080p streaming sweet spot.
• Think of it like taking a wide landscape photo and cropping it to fit a standard frame - your 2K screen (2560x1440) gets smoothly adjusted to 1080p with just a bit of resizing magic.
Encoding Parameters:
• Just to be clear, screenShareEncoding is more about controlling the quality (bitrate and framerate) rather than the actual capture size.
• So with the h1080fps30 preset, you're looking at a max bitrate of 5,000,000 bps and a smooth 30 frames per second.
Actual Streaming Resolution:
The end result? A crisp 1080p stream that looks great, scaled down from your original 2K capture.
Alternative:
Want to keep things exactly as they appear on your screen? No problem! Just use the original preset, which lets you stream at your native resolution without any resizing.
Bottom line: Your 2K screen gets a friendly little makeover to become a 1080p stream, keeping things looking sharp and professional!
Sources: lib/src/participant/local.dart | src/room/track/options.tsabundant-magician-17307
07/28/2025, 3:18 AMtall-airline-16756
07/28/2025, 3:19 AM