本文档将介绍在短视频 SDK 项目中集成和使用 TEBeautyKit 库。
集成步骤
1. 集成 TEBeautyKit,编辑 podfile 文件,添加下面的代码后执行
pod install。# 将S1-07替换成您购买的套餐pod 'TEBeautyKit/S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/TEBeautyKit/latest/TEBeautyKit.podspec'
3. 集成 美颜素材。
使用流程
步骤一:鉴权
[TXUGCBase setLicenceURL:LicenseURL key:LicenseKey];[TEBeautyKit setTELicense:LicenseURL key:LicenseKey completion:^(NSInteger authresult, NSString * _Nullable errorMsg) {NSLog(@"----------result: %zd %@",authresult,errorMsg);}];
步骤二:配置面板资源路径
- (void)configPanel {NSBundle *bundle = [NSBundle mainBundle];NSString *beautyJsonPath = [bundle pathForResource:@"beauty" ofType:@"json"]; //美颜NSString *lutJsonPath = [bundle pathForResource:@"lut" ofType:@"json"]; //滤镜NSString *motion2dJsonPath = [bundle pathForResource:@"motion_2d" ofType:@"json"]; //2d贴纸NSMutableArray *resArray = [[NSMutableArray alloc] init];[resArray addObject:@{TEUI_BEAUTY : beautyJsonPath}];[resArray addObject:@{TEUI_LUT : lutJsonPath}];[resArray addObject:@{TEUI_MOTION_2D : motion2dJsonPath}];/// 设置资源[[TEUIConfig shareInstance] setTEPanelViewResources:resArray];}
步骤三:添加面板
TEPanelView 是自定义的面板视图,用来展示步骤二中配置的数据。
- (void)addPanelView {TEPanelView *tePanelView = [[TEPanelView alloc] init];tePanelView.delegate = self;[self.view addSubview:tePanelView];[tePanelView mas_makeConstraints:^(MASConstraintMaker *make) {make.width.bottom.mas_equalTo(self.view);make.left.right.mas_equalTo(self.view);make.height.mas_equalTo(230 + self.view.safeAreaInsets.bottom);}];}
步骤四:使用美颜
1. 初始化。
- (void)initXMagic {__weak __typeof(self)weakSelf = self;[TEBeautyKit createXMagic:EFFECT_MODE_PRO onInitListener:^(TEBeautyKit * _Nullable beautyKit) {__strong typeof(self)strongSelf = weakSelf;strongSelf.teBeautyKit = beautyKit;strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;[strongSelf.tePanelView setDefaultBeauty];}];}
2. 处理视频数据。
- (GLuint)onPreProcessTexture:(GLuint)texture width:(CGFloat)width height:(CGFloat)height {YTProcessOutput *output = [self.teBeautyKit processTexture:texturetextureWidth:widthtextureHeight:heightwithOrigin:YtLightImageOriginTopLeftwithOrientation:YtLightCameraRotation0];return output.textureData.texture;}
3. 销毁。
- (void)destroyXMagic {[self.teBeautyKit onDestroy];self.teBeautyKit = nil;}