tencent cloud

Feedback

Last updated: 2024-03-19 15:50:12

    SDK Integration

    1. For integrating Tencent Effect SDK, see Integrating Tencent Effect into TRTC SDK.
    2. This documentation explains integrating and using the TEBeautyKit library in the TRTC SDK project.
    3. Refer to demo.

    Utilization of SDK

    Step 1: Integrate TEBeautyKit

    1. Download and extract TEBeautyKit.
    2. Copy the TEBeautyKit folder into your project and make it the same level as the podfile directory.
    3. Edit the podfile and add the following code:
    pod 'TEBeautyKit',:path => 'TEBeautyKit/TEBeautyKit.podspec'

    Step 2: Authenticate

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

    Step 3: Configure the beauty material path

    If the materials configured in the JSON file are local, you need to add the beauty materials to your project.
    - (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"]];
    }

    Step 4: Initialize and add 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);
    }];

    Step 5: Set up the video data callbacks

    [self.trtcCloud setLocalVideoProcessDelegete:self pixelFormat:TRTCVideoPixelFormat_Texture_2D bufferType:TRTCVideoBufferType_Texture];

    Step 6: Create an XMagic object and process video data in the video frame callback interface

    -(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 - TRTCVideoFrameDelegate
    - (uint32_t)onProcessVideoFrame:(TRTCVideoFrame *_Nonnull)srcFrame dstFrame:(TRTCVideoFrame *_Nonnull)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;
    return 0;
    }

    Step 7: Destroy beautification

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

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support