abundant-magician-17307
07/22/2025, 10:28 AMtall-airline-16756
07/22/2025, 10:28 AMtall-airline-16756
07/22/2025, 10:28 AM@livekit/track-processors 包实现。
主要用法如下:
• 使用 VirtualBackground 处理器为本地视频轨道添加虚拟背景:
import { VirtualBackground } from '@livekit/track-processors';
const virtualBackground = VirtualBackground('/path/to/background-image.jpg');
const videoTrack = await createLocalVideoTrack();
await videoTrack.setProcessor(virtualBackground);
• 使用前建议检测浏览器兼容性:
import { supportsBackgroundProcessors, supportsModernBackgroundProcessors } from '@livekit/track-processors';
if(!supportsBackgroundProcessors()) {
throw new Error('this browser does not support background processors');
}
• 虚拟背景支持背景图片和背景模糊,并可在通话中动态切换。
• 需要浏览器支持 OffscreenCanvas、VideoFrame、createImageBitmap 和 WebGL2。
如需 React 示例或更详细的集成方式,可进一步说明。
Sources: src/webgl/index.ts | lib/CameraSettings.tsxabundant-magician-17307
07/22/2025, 10:44 AMtall-airline-16756
07/22/2025, 10:44 AMimport { createLocalVideoTrack } from 'livekit-client';
import { VirtualBackground, supportsBackgroundProcessors } from '@livekit/track-processors';
async function setupVirtualBackground() {
// First things first, let's check if your browser can handle this awesome feature
if (!supportsBackgroundProcessors()) {
throw new Error('Current browser doesn't support background processors - bummer!');
}
// Create your local camera video track
const videoTrack = await createLocalVideoTrack();
// Set up your virtual background - just like magic! 🌈
const virtualBackground = VirtualBackground('/path/to/background-image.jpg');
// Apply that cool background to your video track
await videoTrack.setProcessor(virtualBackground);
// You can then publish this track to your LiveKit room when you're ready
// room.localParticipant.publishTrack(videoTrack);
}
// Just call setupVirtualBackground() and you're all set!
• Pro tip: Replace /path/to/background-image.jpg with the path to your own awesome background image.
• Want to switch things up or turn off the virtual background? Just use videoTrack.stopProcessor().
• Make sure you've got livekit-client and @livekit/track-processors installed - they're your new best friends! 🤝
Need a React example or want to dive deeper? I'm totally here to help - just ask! 👋