tencent cloud

Feedback

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

    Preparations

    1. Download and unzip the demo package. Import the Xmagic module (the files in Bundle, XmagicIconRes, and Record > View folders) into your project.
    2. Import libpag.framework, Masonry.framework, XMagic.framework, and YTCommonXMagic.framework in the lib directory.
    3. For the framework signature, select General and set Masonry.framework and libpag.framework to Embed & Sign.
    4. Set Bundle ID to the bundle ID bound to the trial 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
    • CoreFoundation
    • CoreML
    • JavaScriptCore
    • libc++.tbd
    • libmtasdk.a
    • libresolv.tbd
    • libsqlite3.tbd
    • MetalPerformanceShaders
    Built-in library
    • YTCommon (static authentication library)
    • XMagic (static beauty filter library)
    • libpag (dynamic video decoding library)
    • Masonry (control layout library)
    • QCloudCore (object storage library)
    • QCloudCosXML (object storage library)

    SDK API Integration

    • For steps 12, see the viewDidLoad and buildBeautySDK methods of the UGCKitRecordViewController class in the demo project.
    • For steps 47, see the instance code of the UGCKitRecordViewController and BeautyView classes in the demo project.

    Step 1. Initiate authentication

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

    [TXUGCBase setLicenceURL:LicenseURL key:LicenseKey];
    [TELicenseCheck setTELicense:@"https://license.vod2.myqcloud.com/license/v2/1258289294_1/v_cube.license" key:@"3c16909893f53b9600bc63941162cea3" completion:^(NSInteger authresult, NSString * _Nonnull errorMsg) {
                 if (authresult == TELicenseCheckOk) {
                      NSLog(@"Authentication successful");
                  } else {
                      NSLog(@"Authentication failed");
                  }
          }];
    

    Authentication errorCode description:

    Error Code Description
    0 Succeeded.
    -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.
    Others Contact Tencent Cloud for assistance.

    Step 2. Set the path of SDK materials

    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 preprocessing frame callback, construct YTProcessInput and pass textureId to the SDK for rendering.

    [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