iOS

SDK 集成

1. 集成腾讯特效 SDK,请参考 直播 SDK 集成腾讯特效
2. 本文档说明在直播 SDK 项目中集成和使用 TEBeautyKit 库
3. 参考 demo

SDK 使用

步骤一:集成 TEBeautyKit

1. 下载并解压 TEBeautyKit
2. 把 TEBeautyKit 文件夹拷贝到自己的工程中,和 podfile 同级目录。
3. 编辑 podfile 文件,添加下面的代码:
pod 'TEBeautyKit',:path => 'TEBeautyKit/TEBeautyKit.podspec'

步骤二:鉴权

[TEBeautyKit setTELicense:@"your license" key:@"your key" completion:^(NSInteger authresult, NSString * _Nullable errorMsg) {
NSLog(@"----------result: %zd %@",authresult,errorMsg);
}];

步骤三:配置美颜素材路径

如果 json 文件中配置的素材是本地的,需要将美颜素材添加到工程中。
- (void)initBeautyJson{
NSString *resourcePath = [[NSBundle mainBundle]
pathForResource:@"TEBeautyKitResources" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:resourcePath];
[[TEUIConfig shareInstance] setTEPanelViewRes:[bundle pathForResource:@"beauty_S1" ofType:@"json"]
beautyBody:[bundle pathForResource:@"beauty_body" ofType:@"json"]
lut:[bundle pathForResource:@"lut" ofType:@"json"]
motion:[bundle pathForResource:@"motions" ofType:@"json"]
makeup:[bundle pathForResource:@"makeup" ofType:@"json"]
segmentation:[bundle pathForResource:@"segmentation" ofType:@"json"]];
}

步骤四:初始化并添加 TEPanelView

-(TEPanelView *)tePanelView{
if (!_tePanelView) {
_tePanelView = [[TEPanelView alloc] init:nil comboType:nil];
_tePanelView.delegate = self;
}
return _tePanelView;
}
[self.view addSubview:self.tePanelView];
[self.tePanelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.view);
make.centerX.mas_equalTo(self.view);
make.height.mas_equalTo(250);
make.bottom.mas_equalTo(self.view.mas_bottom);
}];

步骤五:设置视频数据回调

[self.livePusher enableCustomVideoProcess:true pixelFormat:V2TXLivePixelFormatTexture2D bufferType:V2TXLiveBufferTypeTexture];

步骤六:在视频帧回调接口中创建 XMagic 对象和处理视频数据

-(void)initXMagic{
__weak __typeof(self)weakSelf = self;
[TEBeautyKit create:^(XMagic * _Nullable api) {
__strong typeof(self) strongSelf = weakSelf;
strongSelf.xMagicKit = api;
[strongSelf.teBeautyKit setXMagicApi:api];
strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;
[strongSelf.teBeautyKit setTePanelView:strongSelf.tePanelView];
[strongSelf.teBeautyKit setLogLevel:YT_SDK_ERROR_LEVEL];
strongSelf.tePanelView.beautyKitApi = api;
[strongSelf.xMagicKit registerSDKEventListener:strongSelf];
}];
}
#pragma mark - V2TXLivePusherObserver
- (void)onProcessVideoFrame:(V2TXLiveVideoFrame *)srcFrame dstFrame:(V2TXLiveVideoFrame *)dstFrame {
if(!_xMagicKit){
[self initXMagic];
}
YTProcessOutput *output = [self.teBeautyKit processTexture:srcFrame.textureId textureWidth:srcFrame.width textureHeight:srcFrame.height withOrigin:YtLightImageOriginTopLeft withOrientation:YtLightCameraRotation0];
dstFrame.textureId = output.textureData.texture;
}


步骤七:销毁美颜

- (void)destroyXMagic{
[self.xMagicKit clearListeners];
[self.xMagicKit deinit];
self.xMagicKit = nil;
}