公司是内网的livekit环境,现在做web虚拟背景的时候,会访问互联网地址不通,可以将web虚拟背...
# ask-ai
a
公司是内网的livekit环境,现在做web虚拟背景的时候,会访问互联网地址不通,可以将web虚拟背景用到的互联网地址文件下载到本地配置吗?需要自定义配置哪些文件https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.14/wasm/vision_wasm_internal.jsh
t
Thanks for reaching out, 徐旭. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
在内网环境下使用LiveKit Web虚拟背景功能时,可以将依赖的互联网资源下载到本地并通过配置实现离线加载。具体步骤如下: • 下载依赖文件: ◦ 从
<https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.14/wasm/>
下载以下文件: ▪︎ vision_wasm_internal.js ▪︎ vision_wasm_internal.wasm ▪︎ vision_wasm_nosimd_internal.js ▪︎ vision_wasm_nosimd_internal.wasm ◦ 从
<https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite>
下载模型文件
selfie_segmenter.tflite
• 本地目录结构建议:
Copy code
public/
├── mediapipe/
│   ├── wasm/
│   │   ├── vision_wasm_internal.js
│   │   ├── vision_wasm_internal.wasm
│   │   ├── vision_wasm_nosimd_internal.js
│   │   └── vision_wasm_nosimd_internal.wasm
│   └── models/
│       └── selfie_segmenter.tflite
• 代码中自定义配置:
Copy code
import { BackgroundProcessor } from '@livekit/track-processors';

const backgroundProcessor = new BackgroundProcessor({
  assetPaths: {
    tasksVisionFileSet: '/mediapipe/wasm',
    modelAssetPath: '/mediapipe/models/selfie_segmenter.tflite'
  }
});
注意事项: • 确保下载的wasm和模型文件版本与@mediapipe/tasks-vision依赖版本一致 • Web服务器需正确配置CORS,允许加载wasm文件 • 生产环境建议使用HTTPS,且需现代浏览器支持WebGL2等特性 通过上述方式即可在内网环境下使用LiveKit虚拟背景,无需访问外部CDN或Google Storage。 Sources: pnpm-lock.yaml
a
const virtualBg = VirtualBackground('/path/to/background.jpg', { assetPaths: { tasksVisionFileSet: '/mediapipe/wasm', modelAssetPath: '/mediapipe/models/selfie_segmenter.tflite' } });这样写正确吗,assetPaths还需要配置什么吗?
t
Hey there! When setting up
VirtualBackground
, you only need to focus on two key fields in the
assetPaths
configuration:
tasksVisionFileSet
and
modelAssetPath
. No need to complicate things! Here's how you'll want to write it:
Copy code
const virtualBg = VirtualBackground('/path/to/background.jpg', {
  assetPaths: {
    tasksVisionFileSet: '/mediapipe/wasm',
    modelAssetPath: '/mediapipe/models/selfie_segmenter.tflite'
  }
});
As long as your
/mediapipe/wasm
directory has the necessary wasm files and the
/mediapipe/models/selfie_segmenter.tflite
path is correct, you're all set! This simple setup will work like a charm. Pro tip: If you don't need any custom models or resources, you can even skip the
assetPaths
altogether. The system will happily use the default CDN paths for you. Sources: README.md
a
我想要自定义assetPaths,使用本地的文件。但是实际使用时配置的assetPaths没有生效,使用的还是default CDN paths
t
Hey there! Having trouble with assetPaths configuration? No worries, I've got your back. Let me walk you through some common reasons and troubleshooting tips. • Version Check: First things first, make sure you're using
@livekit/track-processors
version 0.5.1 or newer. Older versions won't play nice with assetPaths. Quick tip: run
npm list @livekit/track-processors
to see your current version. • Configuration Format: Your assetPaths should look exactly like this:
Copy code
{
  tasksVisionFileSet: '/mediapipe/wasm',
  modelAssetPath: '/mediapipe/models/selfie_segmenter.tflite'
}
• Passing the Configuration: When calling
VirtualBackground
or
BackgroundProcessor
, remember to pass assetPaths as the fourth parameter (ProcessorWrapperOptions). Here's an example to help you out:
Copy code
const virtualBg = VirtualBackground(
  '/path/to/background.jpg',
  undefined,
  undefined,
  {
    assetPaths: {
      tasksVisionFileSet: '/mediapipe/wasm',
      modelAssetPath: '/mediapipe/models/selfie_segmenter.tflite'
    }
  }
);
• Path Accessibility: Double-check that your local paths are browser-friendly. If not, it'll default back to the CDN path. • Debugging Tip: Use your browser's developer tools (Network tab) to peek at which resources are actually being loaded. It'll help you confirm if your custom paths are working. Pro tip: Focus on getting that version number right and making sure you're passing those assetPaths correctly. You've got this! 💪 Sources: vite.config.ts
a
const virtualBg = VirtualBackground( '/path/to/background.jpg', undefined, undefined, { assetPaths: { tasksVisionFileSet: '/mediapipe/wasm', modelAssetPath: '/mediapipe/models/selfie_segmenter.tflite' } } );其中assetPaths应该作为第四个参数,还是第二个参数
t
Hey there! Let me walk you through the
VirtualBackground
function's parameters in a friendly way. 😊 1. imagePath: string 2. segmenterOptions?: SegmenterOptions 3. onFrameProcessed?: (stats: FrameProcessingStats) => void 4. processorOptions?: ProcessorWrapperOptions(包含 assetPaths) Here's the key thing to remember: assetPaths should be passed as the 4th parameter. Let me show you an example that'll make it crystal clear:
Copy code
const virtualBg = VirtualBackground(
  '/path/to/background.jpg',
  undefined,
  undefined,
  {
    assetPaths: {
      tasksVisionFileSet: '/mediapipe/wasm',
      modelAssetPath: '/mediapipe/models/selfie_segmenter.tflite'
    }
  }
);
Just set it up like this, and you're good to go! Just a heads up – don't try to sneak assetPaths in as the 2nd parameter. 👍 Sources: README.md
a
@livekit/track-processors
包中
VirtualBackground
函数的源码文件,我想看一下`VirtualBackground的定义`
t
Hey there! Let me walk you through the
@livekit/track-processors
package's
VirtualBackground
function, which you'll find in the src/index.ts file. It's pretty neat! 😊
Copy code
export const VirtualBackground = (
  imagePath: string,
  segmenterOptions?: SegmenterOptions,
  onFrameProcessed?: (stats: FrameProcessingStats) => void,
  processorOptions?: ProcessorWrapperOptions,
) => {
  return BackgroundProcessor(
    {
      imagePath,
      segmenterOptions,
      onFrameProcessed,
      ...processorOptions,
    },
    'virtual-background',
  );
};
Here's the scoop: this function actually calls
BackgroundProcessor
, putting together all the parameters and returning a processor instance. Pretty straightforward, right? 👍 Sources: src/transformers/index.ts
a
ProcessorWrapperOptions源码给一下,我想看看它有哪些参数
t
Hey there! Let me walk you through the
ProcessorWrapperOptions
interface. It's pretty straightforward and designed to give you some flexibility.
Copy code
export interface ProcessorWrapperOptions {
  /**
   * Maximum frame rate for fallback canvas.captureStream implementation
   * Default: 30
   */
  maxFps?: number;
}
So, what's cool about this is it has just one optional parameter: • maxFps?: number —— This lets you control the maximum frame rate when using a fallback
canvas.captureStream
implementation. By default, it's set to 30, but you can adjust it to suit your needs. Just to give you a bit more context, this interface is used by others like
BackgroundProcessorOptions
to help manage performance settings for fallback implementations. Pretty handy, right? Sources: src/transformers/types.ts
a
使用安卓虚拟背景demo示例,做出来的效果是人的面部轮廓不完整,怎么优化,给出代码示例
t
Hey there! Having trouble with incomplete face outlines in the Android LiveKit virtual background demo? No worries – I've got some friendly tips to help you smooth things out! 1. Tweak the Segmenter Settings:
Copy code
val options = SelfieSegmenterOptions.Builder()
    .setDetectorMode(SelfieSegmenterOptions.STREAM_MODE)
    .build()
segmenter = Segmentation.getClient(options)
Feel free to play around with the
SelfieSegmenterOptions
parameters to find what works best for you. 2. Smooth Out Those Edges:
Copy code
float edgeSoftness = 6.0; // Increasing this value can make edges softer
float smoothAlpha = smoothstep(0.5 - grad * edgeSoftness, 0.5 + grad * edgeSoftness, maskVal);
In the
CompositeShader
, adjusting
edgeSoftness
can really help refine your profile outline. 3. Fine-Tune Background Blur:
Copy code
class VirtualBackgroundTransformer(
    val blurRadius: Float = 16f,
    val downSampleFactor: Int = 2,
)
Experiment with
blurRadius
and
downSampleFactor
to get that perfect visual vibe. Pro tip: Take your time and adjust these settings gradually. Every little tweak can make a big difference in getting that crisp, clean virtual background look! Sources: video-encode-decode-test/src/main/res/drawable/ic_launcher_background.xml