腾讯特效SDKiOS_音视频解决方案_同尘科技

腾讯特效SDK 2年前 (2023-05-15) 浏览 49

集成准备

1. 下载并解压 Demo 包,将 Demo 工程中的 xmagic 模块(bundle,XmagicIconRes,Xmagic 文件夹)导入到实际项目工程中。2. 如果使用的 XMagic SDK 版本在2.5.0之前,导入 SDK 目录中的 libpag.frameworkMasonry.frameworkXMagic.frameworkYTCommonXMagic.framework如果使用的 XMagic SDK 版本在2.5.1及以后,导入 SDK 目录中的 libpag.frameworkMasonry.frameworkXMagic.frameworkYTCommonXMagic.frameworkAudio2Exp.frameworkTEFFmpeg.framework(version3.0.0以后,改名为:TECodec.framework)。3. framework 签名 General–> Masonry.frameworklibpag.frameworkEmbed & SignYTCommonXMagic.framework 在版本2.5.1之前选 Do Not Embed,在版本2.5.1及以后选 Embed & Sign。4. 将 Bundle ID 修改成与申请的测试授权一致。

开发者环境要求

开发工具 XCode 14 及以上:App Store 或单击 下载地址。建议运行环境:设备要求:iPhone 5 及以上;iPhone 6 及以下前置摄像头最多支持到 720p,不支持 1080p。系统要求:iOS 10.0 及以上。

C/C++层开发环境

XCode 默认 C++ 环境。

类型 依赖库
系统依赖库 AccelerateAssetsLibraryAVFoundationCoreMedia CoreFoundationCoreMLFoundationJavaScriptCorelibc++.tbdlibz.blibresolv.tbdlibsqlite3.0.tbdMetalPerformanceShadersMetalKitMobileCoreServicesOpneALOpneGLESSecurityReplayKitSystemConfigurationUIKit
自带的库 YTCommon(鉴权静态库)XMagic(美颜静态库)libpag(视频解码动态库)Masonry(控件布局库)TXLiteAVSDK_ProfessionalTXFFmpeg(version3.0.0以后,改名为:TECodec.framework)TXSoundTouchAudio2Exp(xmagic sdk version在2.5.1及以后的版本才有)TEFFmpeg(xmagic sdk version在2.5.1及以后的版本才有)

SDK 接口集成

步骤一 和 步骤二 可参考 Demo 工程中,ThirdBeautyViewControllerviewDidLoadbuildBeautySDK 方法;AppDelegate类的application方法进行了Xmagic鉴权。步骤四 至 步骤七 可参考 Demo 工程的 ThirdBeautyViewControllerBeautyView 类相关示例代码。

步骤一:初始化授权

XMagic 鉴权:在相关业务模块的初始化代码中设置 URL 和 KEY,触发 License 下载,避免在使用前才临时去下载。也可以在 AppDelegatedidFinishLaunchingWithOptions 方法里触发下载。其中,LicenseURLLicenseKey 是控制台绑定 License 时生成的授权信息。SDK 版本在2.5.1以前,TELicenseCheck.hXMagic.framework里面;SDK 版本在2.5.1及以后,TELicenseCheck.hYTCommonXMagic.framework里面。

[TELicenseCheck setTELicense:LicenseURL key:LicenseKey completion:^(NSInteger authresult, NSString * _Nonnull errorMsg) {    if (authresult == TELicenseCheckOk) {         NSLog(@"鉴权成功");     } else {         NSLog(@"鉴权失败");     } }];

鉴权 errorCode 说明

错误码 说明
0 成功。Success
-1 输入参数无效,例如 URL 或 KEY 为空
-3 下载环节失败,请检查网络设置
-4 从本地读取的 TE 授权信息为空,可能是 IO 失败引起
-5 读取 VCUBE TEMP License文件内容为空,可能是 IO 失败引起
-6 v_cube.license 文件 JSON 字段不对。请联系腾讯云团队处理
-7 签名校验失败。请联系腾讯云团队处理
-8 解密失败。请联系腾讯云团队处理
-9 TELicense 字段里的 JSON 字段不对。请联系腾讯云团队处理
-10 从网络解析的 TE 授权信息为空。请联系腾讯云团队处理
-11 把TE授权信息写到本地文件时失败,可能是 IO 失败引起
-12 下载失败,解析本地 asset 也失败
-13 鉴权失败
其他 请联系腾讯云团队处理

步骤二:设置 SDK 素材资源路径

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};// 初始化SDK:width和height分别是texture的宽高self.xMagicKit = [[XMagic alloc] initWithRenderSize:CGSizeMake(width,height) assetsDict:assetsDict];

步骤三:添加日志和事件监听

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

步骤四:配置美颜各种效果(详细美颜效果配置请参考 美颜参数说明 和 Demo)

// @brief 配置美颜各种效果// @param propertyType 效果类型 字符串:beauty, lut, motion// @param propertyName 效果名称// @param propertyValue 效果数值// @param extraInfo 预留扩展, 附加额外配置dict// @return 成功返回0,失败返回其他- (int)configPropertyWithType:(NSString *_Nonnull)propertyType withName:(NSString *_Nonnull)propertyName withData:(NSString*_Nonnull)propertyValue withExtraInfo:(id _Nullable)extraInfo;

步骤五:进行渲染处理

TRTC SDK 设置第三方美颜的视频数据回调:设置该回调之后,TRTC SDK 会把采集到的视频帧通过您设置的 delegate 回调出来,用于第三方美颜组件进行二次处理。

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

在视频帧回调接口 onProcessVideoFrame:(TRTCVideoFrame *_Nonnull)srcFrame dstFrame:(TRTCVideoFrame *_Nonnull)dstFrame中,构造 YTProcessInput 传入到 SDK 内做渲染处理,可参考 Demo 中的 ThirdBeautyViewController。

#pragma mark - TRTCVideoFrameDelegate- (uint32_t)onProcessVideoFrame:(TRTCVideoFrame *_Nonnull)srcFrame dstFrame:(TRTCVideoFrame *_Nonnull)dstFrame {    if (!self.xMagicKit) {        [self buildBeautySDK:srcFrame.width and:srcFrame.height texture:srcFrame.textureId];//初始化XMagic SDK        self.heightF = srcFrame.height;        self.widthF = srcFrame.width;    }    if(self.xMagicKit!=nil && (self.heightF!=srcFrame.height || self.widthF!=srcFrame.width)){       self.heightF = srcFrame.height;       self.widthF = srcFrame.width;       [self.xMagicKit setRenderSize:CGSizeMake(srcFrame.width, srcFrame.height)];    }    YTProcessInput *input = [[YTProcessInput alloc] init];    input.textureData = [[YTTextureData alloc] init];    input.textureData.texture = srcFrame.textureId;    input.textureData.textureWidth = srcFrame.width;    input.textureData.textureHeight = srcFrame.height;    input.dataType = kYTTextureData;    YTProcessOutput *output = [self.xMagicKit process:input withOrigin:YtLightImageOriginTopLeft withOrientation:YtLightCameraRotation0];    dstFrame.textureId = output.textureData.texture;    return 0;}

步骤六:暂停/恢复/销毁 SDK

//暂停SDK[self.xMagicKit onPause];//恢复SDK[self.xMagicKit onResume];//销毁SDK[self.xMagicKit clearListeners];[self.xMagicKit deinit]; self.xMagicKit = nil;

步骤七:布局中添加 SDK 美颜面板

UIEdgeInsets gSafeInset;#if __IPHONE_11_0 && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0if(gSafeInset.bottom > 0){}if (@available(iOS 11.0, *)) {    gSafeInset = [UIApplication sharedApplication].keyWindow.safeAreaInsets;} else#endif    {        gSafeInset = UIEdgeInsetsZero;    }
dispatch_async(dispatch_get_main_queue(), ^{ //美颜选项界面 self.beautyContainer = [[BeautyView alloc] init]; [self.view addSubview:self.beautyContainer]; [self.beautyContainer 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){ // 适配全面屏 make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(0); } else { make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(-10); } }];});



对音视频的解决方案有疑惑?想了解解决方案收费? 联系解决方案专家

腾讯云限时活动1折起,即将结束: 马上收藏

同尘科技为腾讯云授权服务中心,购买腾讯云享受折上折,更有现金返利:同意关联,立享优惠

阿里云解决方案也看看?: 点击对比阿里云的解决方案

- 0人点赞 -

发表点评 (0条)

not found

暂无评论,你要说点什么吗?