tencent cloud

Feedback

Last updated: 2022-07-25 15:05:50

    Directions

    1. Download and unzip the demo package.
    2. Import the xMagic module (bundle, XmagicIconRes, and Xmagic folders) from the demo project into your actual project.
    3. Import libpag.framework, Masonry.framework, XMagic.framework, and YTCommonXMagic.framework in the SDK directory.
    4. For the framework signature, select General and set Masonry.framework and libpag.framework to Embed & Sign.
    5. Replace the Bundle ID with the one under the obtained license.

    Developer environment requirements

    • Xcode 11 or later: Download on App Store or here.
    • Recommended runtime environment:
      • Device requirements: iPhone 5 or later. iPhone 6 and older models support up to 720p for front camera.
      • System requirements: iOS 10.0 or later.

    C/C++ layer development environment

    Xcode uses the C++ environment by default.

    TypeDependency Library
    System dependent library
    • Accelerate
    • AssetsLibrary
    • AVFoundation
    • CoreMedia
    • CoreFoundation
    • CoreML
    • Foundation
    • JavaScriptCore
    • libc++.tbd
    • libz.b
    • libresolv.tbd
    • libsqlite3.0.tbd
    • MetalPerformanceShaders
    • MetalKit
    • MobileCoreServices
    • OpneAL
    • OpneGLES
    • ReplayKit
    • SystemConfiguration
    • UIKit
    Built-in library
    • YTCommon (static authentication library)
    • XMagic (static beauty filter library)
    • libpag (dynamic video decoding library)
    • Masonry (control layout library)
    • TXLiteAVSDK_Professional
    • TXFFmpeg
    • TXSoundTouch

    SDK API Integration

    • For steps 12, see the viewDidLoad and buildBeautySDK methods of the ThirdBeautyViewController class in the demo project. The application method of the AppDelegate class performs xMagic authentication.
    • For steps 47, see the instance code of the ThirdBeautyViewController and BeautyView classes in the demo project.

    Step 1. Initialize authorization

    1. Add the following authentication code to didFinishLaunchingWithOptions of AppDelegate (set LicenseURL and LicenseKey according to the authorization information you obtain from the Tencent Cloud website):

      [TXLiveBase setLicenceURL:LicenseURL key:LicenseKey];
      
    2. xMagic authentication: Set the URL and KEY in the initialization code of the relevant business module to trigger the license download. Avoid downloading it just before use. You can also trigger the download in the didFinishLaunchingWithOptions method of the AppDelegate. Here, LicenseURL and LicenseKey are the information generated in the console when the license is bound.

      [TELicenseCheck setTELicense:LicenseURL key:LicenseKey completion:^(NSInteger authresult, NSString * _Nonnull errorMsg) {
         if (authresult == TELicenseCheckOk) {
              NSLog(@"Authentication successful");
          } else {
              NSLog(@"Authentication failed");
          }
      }];
      

    Authentication errorCode description:

    Error Code Description
    0 Success.
    -1 The input parameter is invalid; for example, the `URL` or `KEY` is empty.
    -3 Download failed. Check the network settings.
    -4 The Tencent Effect SDK authorization information read from the local system is empty, which may be caused by an I/O failure.
    -5 The content of read VCUBE TEMP license file is empty, which may be caused by an I/O failure.
    -6 The JSON field in the `v_cube.license` file is incorrect. Contact Tencent Cloud for assistance.
    -7 Signature verification failed. Contact Tencent Cloud for assistance.
    -8 Decryption failed. Contact Tencent Cloud for assistance.
    -9 The JSON field in the `TELicense` field is incorrect. Contact Tencent Cloud for assistance.
    -10 The Tencent Effect SDK authorization information parsed online is empty. Contact Tencent Cloud for assistance.
    -11 Failed to write the Tencent Effect SDK authorization information to the local file, which may be caused by an I/O failure.
    -12 Failed to download and failed to parse local assets.
    -13 Authentication failed.
    Other Contact Tencent Cloud for assistance.

    Step 2. Set the SDK material resource path

    CGSize previewSize = [self getPreviewSizeByResolution:self.currentPreviewResolution];
    NSString *beautyConfigPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    beautyConfigPath = [beautyConfigPath stringByAppendingPathComponent:@"beauty_config.json"];
    NSFileManager *localFileManager=[[NSFileManager alloc] init];
    BOOL isDir = YES;
    NSDictionary * beautyConfigJson = @{};
    if ([localFileManager fileExistsAtPath:beautyConfigPath isDirectory:&isDir] && !isDir) {
    NSString *beautyConfigJsonStr = [NSString stringWithContentsOfFile:beautyConfigPath encoding:NSUTF8StringEncoding error:nil];
    NSError *jsonError;
    NSData *objectData = [beautyConfigJsonStr dataUsingEncoding:NSUTF8StringEncoding];
    beautyConfigJson = [NSJSONSerialization JSONObjectWithData:objectData
                                            options:NSJSONReadingMutableContainers
                                            error:&jsonError];
    }
    NSDictionary *assetsDict = @{@"core_name":@"LightCore.bundle",
                            @"root_path":[[NSBundle mainBundle] bundlePath],
                            @"tnn_"
                            @"beauty_config":beautyConfigJson
    };
    // Init beauty kit
    self.beautyKit = [[XMagic alloc] initWithRenderSize:previewSize assetsDict:assetsDict];
    

    Step 3. Add the log and event listener

       // Register log
       [self.beautyKit registerSDKEventListener:self];
       [self.beautyKit registerLoggerListener:self withDefaultLevel:YT_SDK_ERROR_LEVEL];
    

    Step 4. Configure beauty filter effects

    - (int)configPropertyWithType:(NSString *_Nonnull)propertyType withName:(NSString *_Nonnull)propertyName withData:(NSString*_Nonnull)propertyValue withExtraInfo:(id _Nullable)extraInfo;
    

    Step 5. Render videos

    In the video frame callback API, construct and pass YTProcessInput to the SDK for rendering. You can refer to ThirdBeautyViewController in the demo.

    [self.xMagicKit process:inputCPU withOrigin:YtLightImageOriginTopLeft withOrientation:YtLightCameraRotation0]
    

    Step 6. Pause/Resume the SDK

    [self.beautyKit onPause];
    [self.beautyKit onResume];
    

    Step 7. Add the SDK beauty filter panel to the layout

    UIEdgeInsets gSafeInset;
    #if __IPHONE_11_0 && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
    if(gSafeInset.bottom > 0){
    }
    if (@available(iOS 11.0, *)) {
    gSafeInset = [UIApplication sharedApplication].keyWindow.safeAreaInsets;
    } else
    #endif
    {
    gSafeInset = UIEdgeInsetsZero;
    }
    dispatch_async(dispatch_get_main_queue(), ^{
    // Beauty filter option UI
    _vBeauty = [[BeautyView alloc] init];
    [self.view addSubview:_vBeauty];
    [_vBeauty mas_makeConstraints:^(MASConstraintMaker *make) {
    make.width.mas_equalTo(self.view);
    make.centerX.mas_equalTo(self.view);
    make.height.mas_equalTo(254);
    if(gSafeInset.bottom > 0.0){  // Adapt to full-view screen
        make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(0);
    } else {
        make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(-10);
    }
    }];
    _vBeauty.hidden = YES;
    });
    
    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