@cloudflare/realtimekit-virtual-background

中文文档
0.0.3发布于 2026/10/19TypeScriptESM + CJS零依赖近 30 天下载 17.3万
原始使用文档
文档目录8 节
  1. RealtimeKit Video Background Transformer
  2. Table of Contents
  3. About The Project
  4. Built With
  5. Getting Started
  6. Installation
  7. Run the example
  8. Usage

Logo

RealtimeKit Video Background Transformer

A package that adds video background & blur to participant video feeds in your RealtimeKit Meetings.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About The Project

This package provides the foundation to add video background and blur to a participant's video feed in your RealtimeKit Meeting with your custom UI implementation.

If you are using the rtk-meeting component directly and prefer abstraction over this package, refer to UI Kit Addons.

Built With

Getting Started

Installation

npm install @cloudflare/realtimekit-virtual-background

Run the example

  1. Run npm install in this repository.
  2. Replace YOUR_AUTH_TOKEN in index.html with a valid RealtimeKit participant token.
  3. Run npm run dev and open http://localhost:3002.
  4. Enable the camera from the setup screen to try the virtual background.

Usage

Disable the default per frame rendering of video middleware to improve speed and quality by letting this middleware control it on its own.

await meeting.self.setVideoMiddlewareGlobalConfig({
  disablePerFrameCanvasRendering: true
});

A videoBackgroundTransformer object can be created using the RealtimeKitVideoBackgroundTransformer.init({meeting: meeting}) method.

const videoBackgroundTransformer = await RealtimeKitVideoBackgroundTransformer.init({
  meeting,
});

Types of middlewares exposed by videoBackgroundTransformer:

  1. createStaticBackgroundVideoMiddleware expects an imageUrl as a parameter and then creates the image the background for the current user.
meeting.self.addVideoMiddleware(
    await videoBackgroundTransformer.createStaticBackgroundVideoMiddleware(imageUrl)
);
  1. createBackgroundBlurVideoMiddleware expects blurStrength (0-100) as a parameter (50% by default) and blurs the background of the user by the given blurStrength.
meeting.self.addVideoMiddleware(
  await videoBackgroundTransformer.createBackgroundBlurVideoMiddleware(50)
);

Note: Some browsers or their old versions might not have support for WebGL or the browser APIs that this package uses. We would recommend checking the support beforehand using:

if(RealtimeKitVideoBackgroundTransformer.isSupported()){
  const videoBackgroundTransformer = await RealtimeKitVideoBackgroundTransformer.init({
    meeting: meeting,
  });
  meeting.self.addVideoMiddleware(
    await videoBackgroundTransformer.createStaticBackgroundVideoMiddleware(`REPLACE_THIS_WITH_IMAGE_URL`)
  );
}

Note: Image URLs must allow CORS to avoid tainting the canvas. You can find such images on https://unsplash.com/ & https://imgur.com.

If in case you want to tweak the segmentation for better, sharper results, Please pass the desired segmentation config while initialising RealtimeKitVideoBackgroundTransformer.

const videoBackgroundTransformer = await RealtimeKitVideoBackgroundTransformer.init({
  meeting,
  segmentationConfig: {
    model: 'mlkit', // 'meet' | 'mlkit'
    backend: 'wasmSimd',
    inputResolution: '256x256', // '256x144' for meet
    pipeline: 'webgl2', // 'webgl2' | 'canvas2dCpu' // canvas2dCpu gives sharper blur, webgl2 is faster.
    targetFps: 35,
  }
});

版本与发布记录

@cloudflare/realtimekit-virtual-background 共发布 7 个版本,首次发布于 2025/05/02;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.0.3latest2026/10/1921 天前
0.0.3-staging.1staging2026/10/1921 天前
0.0.22025/05/291.4 年前
0.0.2-staging.22025/05/091.5 年前
0.0.2-staging.12025/05/091.5 年前
0.0.12025/05/021.5 年前

关于 @cloudflare/realtimekit-virtual-background 的常见问题

如何安装 @cloudflare/realtimekit-virtual-background?

在项目目录运行 npm install @cloudflare/realtimekit-virtual-background,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:bowser(^2.11.0)、@cloudflare/realtimekit(>=1.0.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cloudflare/realtimekit-virtual-background 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cloudflare/realtimekit-virtual-background 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cloudflare/realtimekit-virtual-background 可以商用吗?

@cloudflare/realtimekit-virtual-background 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@cloudflare/realtimekit-virtual-background 的下载量有多少?

根据 npm 官方下载统计,@cloudflare/realtimekit-virtual-background 在 2026/10/10 – 2026/11/08 这 30 天内被下载 173,468 次,日均约 5,782 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cloudflare/realtimekit-virtual-background 还在维护吗?

最新版本 0.0.3 发布于 2026/10/19(21 天前);至今共发布 7 个版本,其中过去 12 个月发布了 2 个;首次发布于 2025/05/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。