Code Monkey home page Code Monkey logo

futrtcdemo's Introduction

FUTRTCDemo 快速接入文档

FUTRTCDemo 是集成了 Faceunity 面部跟踪、虚拟道具功能 和 腾讯实时音视频 SDK的 Demo。

本文是 FaceUnity SDK 快速对接 腾讯实时音视频 的导读说明

关于 FaceUnity SDK 的更多详细说明,请参看 FULiveDemo

快速集成方法

一、导入 SDK

将 FaceUnity 文件夹全部拖入工程中,NamaSDK所需依赖库为 OpenGLES.frameworkAccelerate.frameworkCoreMedia.frameworkAVFoundation.frameworklibc++.tbdCoreML.framework

  • 备注: 示例demo NamaSDK 使用 Pods 管理 会自动添加依赖,运行在iOS11以下系统时,需要手动添加CoreML.framework,并在TARGETS -> Build Phases-> Link Binary With LibrariesCoreML.framework手动修改为可选Optional

FaceUnity 模块简介

+Lib              //FURenderKit动态库、鉴权文件和文件资源
+Demo             //集成实例demo
      

二、加入展示 FaceUnity SDK 美颜贴纸效果的 UI

1、在 TRTRCRoomViewController.m 中添加头文件,并创建页面属性

/**faceU */
#import "FUDemoManager.h"

#import <FURenderKit/FUGLContext.h>

// 使用纹理渲染时,记录当前glcontext
@property(nonatomic, strong) EAGLContext *mContext;

2、在 viewDidLoad 中初始化 FaceUnity的界面和 SDK

    [FUDemoManager setupFaceUnityDemoInController:self originY:CGRectGetHeight(self.view.frame) - FUBottomBarHeight - safeAreaBottom - 60];

三、在 enterRoom 方法中,进入房间之前设置本地视频的自定义渲染回调

NSDictionary *dict = @{
                            @"api" : @"setCustomRenderMode",
                            @"params" : @{@"mode" : @(1)}
                        };

[self.trtc callExperimentalAPI:[NSString convertToJsonData:dict]];
[self.trtc setLocalVideoRenderDelegate:self pixelFormat:(TRTCVideoPixelFormat_NV12) bufferType:(TRTCVideoBufferType_PixelBuffer)];

四、在本地视频的自定义渲染回调中,FaceUnity处理视频数据(FURenderInput输入和FURenderOutput输出)

- (uint32_t)onProcessVideoFrame:(TRTCVideoFrame *)srcFrame dstFrame:(TRTCVideoFrame *)dstFrame{
    _mContext = [EAGLContext currentContext];
    if ([FUGLContext shareGLContext].currentGLContext != _mContext) {
        [[FUGLContext shareGLContext] setCustomGLContext: _mContext];
    }
    
    if ([FUManager shareManager].isRender) {
        [[FUTestRecorder shareRecorder] processFrameWithLog];
        [[FUManager shareManager] updateBeautyBlurEffect];
        FURenderInput *input = [[FURenderInput alloc] init];
        
        // 根据输入纹理调整参数设置
        input.renderConfig.imageOrientation = FUImageOrientationDown;
        input.renderConfig.isFromFrontCamera = self.isFrontCamera;
        input.renderConfig.isFromMirroredCamera = YES;
        // stickerFlipH和stickerFlipV尽量不要使用,后续将不再维护,这里使用是为了适配老道具
        input.renderConfig.stickerFlipH = !self.isFrontCamera;
        input.renderConfig.stickerFlipV = NO;
        
        FUTexture tex = {srcFrame.textureId, CGSizeMake(srcFrame.width, srcFrame.height)};
        input.texture = tex;
        // 开启重力感应,内部会自动计算正确方向,设置fuSetDefaultRotationMode,无须外面设置
        input.renderConfig.gravityEnable = YES;
        input.renderConfig.textureTransform = CCROT0_FLIPVERTICAL;
        FURenderOutput *output = [[FURenderKit shareRenderKit] renderWithInput:input];
        dstFrame.textureId = output.texture.ID;
        if (output.texture.ID != 0) {
            return output.texture.ID;;
        }
    }
    return 0;
}

五、销毁道具

1 视图控制器生命周期结束时,销毁道具

[[FUManager shareManager] destoryItems];

2 切换摄像头需要调用,切换摄像头

[[FUManager shareManager] onCameraChange];

关于 FaceUnity SDK 的更多详细说明,请参看 FULiveDemo

futrtcdemo's People

Contributors

jdbbjd avatar kurtchen1988 avatar xiangxiaopenyou avatar liufengcoder avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.