rtc-beauty-plugin
Advanced tools
Comparing version
{ | ||
"name": "rtc-beauty-plugin", | ||
"version": "0.0.7", | ||
"version": "0.1.0", | ||
"description": "rtc-beauty-plugin for TRTC SDK", | ||
@@ -5,0 +5,0 @@ "main": "rtc-beauty-plugin.js", |
107
README.md
## 功能描述 | ||
TRTC 可以通过插件,帮助开发者轻松实现基础美颜功能。用户可以调整美颜参数,实现自然的美颜效果。[点击此处](https://web.sdk.qcloud.com/trtc/webrtc/demo/api-sample/improve-beauty.html) 体验美颜效果。 | ||
TRTC 可以通过插件,帮助开发者轻松实现基础美颜功能。用户可以调整美颜参数,实现自然的美颜效果。 | ||
也可以通过插件来对视频增加人像分割的处理,在通话过程中呈现背景虚化或者虚拟背景的效果。 | ||
[点击此处](https://web.sdk.qcloud.com/trtc/webrtc/demo/api-sample/improve-beauty.html) 体验效果。 | ||
@@ -16,3 +18,9 @@ | 浏览器 | 版本 | | ||
除了以上支持的平台,其他平台均不支持 | ||
- 除了以上支持的平台,其他平台均不支持 | ||
- 美颜和人像分割的计算和渲染都是比较消耗性能的,因此如果使用者的设备性能不足以支撑运算,建议不开启美颜和人像分割的功能。 | ||
- 2.6 GHz 六核Intel Core i7 16G 内存处理器的设备性能数据: | ||
- 480p 15帧的视频,使用美颜处理时,占用 CPU 比正常音视频通话要多 10% 左右。 | ||
- 480p 15帧的视频,使用背景虚化处理时,占用 CPU 比正常音视频通话要多 25% 左右。 | ||
- 480p 15帧的视频,使用虚拟背景处理时,占用 CPU 比正常音视频通话要多 30% 左右,如果自定义背景的分辨率过高的话,可能会导致性能消耗进一步增高。 | ||
@@ -23,4 +31,7 @@ ## 接入攻略 | ||
使用 `RTCBeautyPlugin` 时,请将 TRTC SDK 升级到 4.11.1 及以上版本。 | ||
**如果您需要使用 `RTCBeautyPlugin` 的美颜能力时,请将 TRTC SDK 升级到 4.11.1 及以上版本。** | ||
**如果您需要使用 `RTCBeautyPlugin` 的人像分割能力时,请将 TRTC SDK 升级到 4.11.10 及以上版本。** | ||
在项目中安装 [RTCBeautyPlugin](https://www.npmjs.com/package/rtc-beauty-plugin) 插件。 | ||
@@ -85,3 +96,91 @@ | ||
### destory() | ||
### (async) loadResources() | ||
**功能:** 如果您需要使用人像分割功能,您可以在一开始就调用 loadResources() 方法,来加载人像分割的计算资源。 | ||
```javascript | ||
const rtcBeautyPlugin = new RTCBeautyPlugin(); | ||
// 加载计算资源 | ||
await rtcBeautyPlugin.loadResources(); | ||
``` | ||
### (async) generateVirtualStream({ localStream, type, img }) | ||
将 localStream 处理成经过人像分割处理后的 beautyStream。 | ||
#### Params: | ||
| Name | Type | Description | | ||
|-------------|---------------|------------------------------------------| | ||
| localStream | `LocalStream` | 通过 TRTC.createStream 方法创建的本地流 | | ||
| type | `string` | `blur` 为背景虚化,`virtual`为虚拟背景 | | ||
| img | `HTMLImageElement` | 用于在虚拟背景中生成背景图,建议图片分辨率不超过480p,避免计算时性能开销过大 | | ||
```javascript | ||
// 生成背景虚化的流 | ||
const rtcBeautyPlugin = new RTCBeautyPlugin(); | ||
await rtcBeautyPlugin.loadResources(); | ||
await localStream.initialize(); | ||
const virtualStream = await rtcBeautyPlugin.generateVirtualStream({ | ||
localStream: localStream, | ||
type: 'blur' | ||
}); | ||
await client.publish(virtualStream); | ||
``` | ||
```javascript | ||
// 生成虚拟背景的流 | ||
const rtcBeautyPlugin = new RTCBeautyPlugin(); | ||
await rtcBeautyPlugin.loadResources(); | ||
await localStream.initialize(); | ||
const virtualStream = await rtcBeautyPlugin.generateVirtualStream({ | ||
localStream: localStream, | ||
type: 'virtual', | ||
img: document.getElementById('img'), | ||
}); | ||
await client.publish(virtualStream); | ||
``` | ||
### (async) generateStream({ localStream, type, img }) | ||
生成既有人像分割处理,又有美颜功能的流 | ||
#### Params: | ||
| Name | Type | Description | | ||
|-------------|---------------|------------------------------------------| | ||
| localStream | `LocalStream` | 通过 TRTC.createStream 方法创建的本地流 | | ||
| type | `string` | `blur` 为背景虚化,`virtual`为虚拟背景 | | ||
| img | `HTMLImageElement` | 用于在虚拟背景中生成背景图,建议图片分辨率不超过480p,避免计算时性能开销过大 | | ||
```javascript | ||
const rtcBeautyPlugin = new RTCBeautyPlugin(); | ||
await rtcBeautyPlugin.loadResources(); | ||
await localStream.initialize(); | ||
// 生成人像分割和美颜处理后的流 | ||
const stream = await rtcBeautyPlugin.generateStream({ | ||
localStream: this.localStream_, | ||
type: 'virtual', | ||
img: document.getElementById('img'), | ||
}); | ||
// 发布经过美颜后的流 | ||
await client.publish(stream); | ||
``` | ||
### setBackground(img) | ||
**功能:** 使用人像分割的自定义背景功能时用于动态改变背景图。 | ||
#### Params: | ||
| Name | Type | Description | | ||
|------|--------------|-------------| | ||
| img | `HTMLImageElement` | 用于在虚拟背景中生成背景图,建议图片分辨率不超过480p,避免计算时性能开销过大 | | ||
```javascript | ||
beautyPlugin.setBackground(document.getElementById('newImg')); | ||
``` | ||
### destroy() | ||
**功能:** 销毁美颜插件。 | ||
@@ -88,0 +187,0 @@ |
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
125405
105.89%429
95.89%196
102.06%2
Infinity%5
25%