iOS
This documentation explains integrating and using the TEBeautyKit library in the TRTC SDK project.
Integration Steps
1. (Optional) Integrate TRTCAdapter. The TRTCAdapter.framework is used to receive video callbacks from the TRTC SDK, process them internally using the beauty filter SDK, and then return them to the TRTC SDK. If you need to perform custom processing on the video stream, you can skip this step.
2. Integration TEBeautyKit,Edit the Podfile and append the following code snippet and execution
pod install.# Replace S1-07 with the package you purchased,Note that TEBeautyKit and TencentEffect must use the same packagepod 'TEBeautyKit/S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/TEBeautyKit/latest/TEBeautyKit.podspec'pod 'TencentEffect_S1-07', :podspec => 'https://mediacloud-76607.gzc.vod.tencent-cloud.com/TencentEffect/iOS/podspec/latest/TencentEffect_S1-07.podspec'
3. Integration Panel Resources,download the resource package and incorporate it into your main project. The contents can be found in the appendix.
4. Integration Effect Resources.
Usage Guide
Step 1: Integrated beauty panel
The beauty panel is a custom view control provided by TEBeautyKit. For how to use it, please refer to the TEBeautyKit usage guide.
Step 2: Adapter Binding for Beautification
/// create adapter- (TEBeautyTRTCAdapter *)trtcAdapter {if (!_trtcAdapter) {_trtcAdapter = [[TEBeautyTRTCAdapter alloc] init];}return _trtcAdapter;}/// bind- (void)bind {__weak typeof(self)weakSelf = self;[self.trtcAdapter bind:self.trtcCloud onCreatedXmagicApi:^(XMagic * _Nullable xmagicApi) {__strong typeof(weakSelf)strongSelf = weakSelf;strongSelf.teBeautyKit.xmagicApi = xmagicApi;strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;[strongSelf.tePanelView setDefaultBeauty];} onDestroyXmagicApi:^{__strong typeof(weakSelf)strongSelf = weakSelf;[strongSelf.teBeautyKit onDestroy];strongSelf.teBeautyKit = nil;}];}
Step 3: Parameter Change Notification Adapter
/// Notify the Adapter of the Front and Rear Cameras: Whether to Encode a Mirror Image[self.trtcAdapter notifyCameraChanged:self.isFrontCamera isEncoderMirror:self.isEncoderMirror];/// Notify the Adapter of Screen Orientation Changes[self.trtcAdapter setDeviceOrientation:currOrientation];
Step 4: Unlink the adapter and terminate the beauty enhancement feature
[self.trtcAdapter unbind];self.trtcAdapter = nil;
Step 5: TRTCAdapter is not integrated.
Listen for TRTC video callbacks, process the beauty effects within the callback, and then return the processed video to TRTC.
1. Initialization
- (void)initXMagic {__weak typeof(self)weakSelf = self;[TEBeautyKit createXMagic:EFFECT_MODE_PRO onInitListener:^(TEBeautyKit * _Nullable beautyKit) {__strong typeof(weakSelf)strongSelf = weakSelf;strongSelf.teBeautyKit = beautyKit;strongSelf.tePanelView.teBeautyKit = strongSelf.teBeautyKit;[strongSelf.tePanelView setDefaultBeauty];}];}
2. Processing video data
- (uint32_t)onProcessVideoFrame:(TRTCVideoFrame *)srcFrame dstFrame:(TRTCVideoFrame *)dstFrame {YTProcessOutput *output = [self.teBeautyKit processTexture:srcFrame.textureIdtextureWidth:srcFrame.widthtextureHeight:srcFrame.heightwithOrigin:YtLightImageOriginTopLeftwithOrientation:YtLightCameraRotation0];dstFrame.textureId = output.textureData.texture;return 0;}
3. Destroy Beauty Filter
- (void)destroyXMagic {[self.teBeautyKit onDestroy];self.teBeautyKit = nil;}
