tencent cloud

Feedback

Last updated: 2024-04-09 11:41:07

    SDK Integration

    1. Integrate Tencent Effect SDK. For guidance, refer to Tencent Effect Integration in the integration methods section.
    2. To integrate the TEBeautyKit library, please consider TEBeautyKit / Android on how to integrate modules.
    Refer to TRTC demo project.

    Utilization of SDK

    Step 1: Define the Path

    TEBeautyKit.setResPath((new File(getFilesDir(), "xmagic_dir").getAbsolutePath()));

    Step Two: Setting Panel's JSON File

    Please append the path of the JSON file added to your project in the second step of the 'How to Integrate' section in the TEBeautyKit Integration Document. If there is no JSON file, then the path Setting should be null.
    TEUIConfig.getInstance().setTEPanelViewRes("beauty_panel/beauty.json",null, "beauty_panel/lut.json", "beauty_panel/motions.json", "beauty_panel/makeup.json", "beauty_panel/segmentation.json");

    Step Three: Copying Beauty Resources

    Copy the beauty resources to the path under Step One in Setting, one version only needs to be copied successfully once.
    new Thread(() -> { boolean result = TEBeautyKit.copyRes(MainActivity.this.getApplicationContext()); runOnUiThread(() -> { if (result) { saveCopyData(); } teProgressDialog.dismiss(); checkLicense(); }); }).start();

    Step 4: Authenticate

    TEBeautyKit.setTELicense(this.getApplicationContext(),LicenseConstant.mXMagicLicenceUrl, LicenseConstant.mXMagicKey,(i, s) -> { if (i == LicenseConstant.AUTH_STATE_SUCCEED) { Intent intent = new Intent(MainActivity.this, ThirdBeautyActivity.class); startActivity(intent); } else { Log.e(TAG, "te license check is failed,please checke "); } });

    Step 5: Add Panel

    private void initializeBeautyPanelView() { RelativeLayout panelLayout = findViewById(R.id.live_pusher_bp_beauty_panel); this.elegantPanelView = new TEPanelView(this); if (previousParamList != null) { //To restore the previous beauty effect this.elegantPanelView.setPreviousParamList(previousParamList); } this.elegantPanelView.displayView(this); panelLayout.addView(this.elegantPanelView); }

    Step Six: Create Beauty Feature

    /** * Initialize the beauty filter SDK */ private void initBeautyApi() { TEBeautyKit.create(ThirdBeautyActivity.this.getApplicationContext(), false, new TEBeautyKit.OnInitListener() {
    @Override
    public void onInitResult(TEBeautyKit api) {
    beautyKit = api;
    beautyKit.setTipsListener(new XmagicApi.XmagicTipsListener() {
    @Override
    public void tipsNeedShow(String tips, String tipsIcon, int type, int duration) {
    showTips(tips, tipsIcon, type, duration);
    }
    
    @Override
    public void tipsNeedHide(String tips, String tipsIcon, int type) {
    }
    });
    tePanelView.setupWithTEBeautyKit(beautyKit);
    }
    }); }

    Step Seven: Implementing the Beauty Filter

    private void setProcessListener() {
    //1. Set the `TRTCVideoFrameListener` callback, as outlined in the API documentation {https://liteav.sdk.qcloud.com/doc/api/zh-cn/group__TRTCCloud__android.html#a0b565dc8c77df7fb826f0c45d8ad2d85}
    mTRTCCloud.setLocalVideoProcessListener(TRTCCloudDef.TRTC_VIDEO_PIXEL_FORMAT_Texture_2D, TRTCCloudDef.TRTC_VIDEO_BUFFER_TYPE_TEXTURE, new TRTCCloudListener.TRTCVideoFrameListener() {
    @Override
    public void onGLContextCreated() { //2. GLContext Established
    Log.e(TAG, "onGLContextCreated");
    initBeautyApi();
    }
    
    @Override
    public int onProcessVideoFrame(TRTCCloudDef.TRTCVideoFrame srcFrame, TRTCCloudDef.TRTCVideoFrame dstFrame) {
    if (beautyKit != null) {
    dstFrame.texture.textureId = beautyKit.process(srcFrame.texture.textureId, srcFrame.width, srcFrame.height);
    } else {
    dstFrame.texture.textureId = srcFrame.texture.textureId;
    }
    return 0;
    }
    
    @Override
    public void onGLContextDestory() { //4. GLContext Destruction
    Log.e(TAG, "onGLContextDestroy");
    if (beautyKit != null) {
    beautyKit.onDestroy();
    beautyKit = null;
    }
    }
    });
    }

    Step Eight: Destroying Beauty Effect Note: Requires destruction in the GL thread

    public void onGLContextDestory() { //4. Dismantling of GLContext Log.e(TAG, "onGLContextDestroy"); if (beautyKit != null) { beautyKit.onDestroy(); } }

    Step Nine: Restoring Audio

    /** * Employed to restore the sound in stickers * Reactivate the gyroscope sensor, generally called in Activity's onResume method */ public void onResume()

    Step Ten: Pausing the sound

    /** * Used to pause the sound in stickers * Put the gyroscope sensor on hold, generally called in Activity's onPause method */ public void onPause()
    
    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