一对一直播系统实现美颜预设功能的代码解决方式

发布来源:云豹科技
发布人:云豹科技
2020-12-04 10:01:43

不仅仅是一对一直播系统,其他直播平台、短视频平台对美颜功能的需求都非常的大,今天我们针对一对一直播的美颜预设功能来说一下相关的代码解决方式。此功能主要适用于播端预先设置好美颜、美白、美型灯功能,一对一直播系统进行连麦时直接使用预设好的美颜进行视频通话

1.一对一直播系统在进入预设界面后,首先获取有没有预设过美颜的值:

-(void)requestSetBeauty{
    [YBToolClass postNetworkWithUrl:@"user.getBeauty" andParameter:@{@"uid":[Config getOwnID],@"token":[Config getOwnToken]} success:^(int code, id  _Nonnull info, NSString * _Nonnull msg) {
        NSLog(@"info---------:%@", info);
        NSDictionary *infos = [info firstObject];
        _normalMYDic = [infos valueForKey:@"moren"];
        _xxMYDic = [infos valueForKey:@"meihu"];
        if ([YBToolClass checkNull:[common getTISDKKey]]){
            
            if ([minstr([_normalMYDic valueForKey:@"ishave"]) isEqual:@"1"]) {
                _tx_whitening_level = [[_normalMYDic valueForKey:@"preinstall"][@"skin_whiting"] floatValue];
                _redfacDepth = [[_normalMYDic valueForKey:@"preinstall"][@"skin_tenderness"] floatValue];
                _tx_beauty_level = [[_normalMYDic valueForKey:@"preinstall"][@"skin_smooth"] floatValue];
 
            }
        }else{
            if ([minstr([_xxMYDic valueForKey:@"ishave"]) isEqual:@"1"]) {
                [sproutCommon saveSproutMessage:[_xxMYDic valueForKey:@"preinstall"]];
 
                 _tx_whitening_level = [[_xxMYDic valueForKey:@"preinstall"][@"skin_whiting"] floatValue];
                 _redfacDepth = [[_xxMYDic valueForKey:@"preinstall"][@"skin_tenderness"] floatValue];
                 _tx_beauty_level = [[_xxMYDic valueForKey:@"preinstall"][@"skin_smooth"] floatValue];
                 _light_level = [[_xxMYDic valueForKey:@"preinstall"][@"brightness"] floatValue];
                 _tx_eye_level = [[_xxMYDic valueForKey:@"preinstall"][@"big_eye"] floatValue];
                 _tx_face_level = [[_xxMYDic valueForKey:@"preinstall"][@"face_lift"] floatValue];
                _mouse_level = [[_xxMYDic valueForKey:@"preinstall"][@"mouse_lift"] floatValue];
                 _nose_level = [[_xxMYDic valueForKey:@"preinstall"][@"nose_lift"] floatValue];
                 _xiaba_level = [[_xxMYDic valueForKey:@"preinstall"][@"chin_lift"] floatValue];
                 _head_level = [[_xxMYDic valueForKey:@"preinstall"][@"forehead_lift"] floatValue];
                 _meimao_level = [[_xxMYDic valueForKey:@"preinstall"][@"eye_brow"] floatValue];
                 _yanjiao_level = [[_xxMYDic valueForKey:@"preinstall"][@"eye_corner"] floatValue];
                 _yanju_level = [[_xxMYDic valueForKey:@"preinstall"][@"eye_length"] floatValue];
                 _kaiyanjiao_level = [[_xxMYDic valueForKey:@"preinstall"][@"eye_alat"] floatValue];
                 _xiaolian_level = [[_xxMYDic valueForKey:@"preinstall"][@"face_shave"] floatValue];
                 _longnose_level = [[_xxMYDic valueForKey:@"preinstall"][@"lengthen_noselift"] floatValue];
 
            }


 

2.获取数据后开始推流设置

#pragma mark ============设置推流参数,开始推流=============
 
- (void)RTMPush{
    [self.menuView showMenuView:NO];
    
    [self creatUI];
   
    //配置推流参数
    _txLivePushonfig = [[TXLivePushConfig alloc] init];
    _txLivePushonfig.frontCamera = YES;
    _txLivePushonfig.enableAutoBitrate = YES;
    _txLivePushonfig.videoResolution = VIDEO_RESOLUTION_TYPE_360_640 ;
    //background push
    _txLivePushonfig.pauseFps = 5;
    _txLivePushonfig.pauseTime = 300;
    //耳返
    _txLivePushonfig.enableAudioPreview = NO;
    _txLivePushonfig.pauseImg = [UIImage imageNamed:@"pause_publish1.jpg"];
    _txLivePublisher = [[TXLivePush alloc] initWithConfig:_txLivePushonfig];
     _txLivePublisher.videoProcessDelegate = self;
    _txLivePublisher.delegate = self;
    if ([YBToolClass checkNull:[common getTISDKKey]]){
         isTXfiter = YES;
        
        [_txLivePublisher setBeautyStyle:0 beautyLevel:_tx_beauty_level whitenessLevel:_tx_whitening_level ruddinessLevel:_redfacDepth];
        [_txLivePublisher setMirror:YES];
    }else{
        isTXfiter = NO;
//        NSString *key = [common getTISDKKey];
        NSString *key = [YBToolClass decrypt:[common getTISDKKey]];
 
       [[MHSDK shareInstance] init:key];
     //   [self.menuView setupDefaultBeautyAndFaceValueWithIsTX:YES];
        [_txLivePublisher setMirror:YES];
         _txLivePublisher.videoProcessDelegate = self;
    }
     [_txLivePublisher startPreview:_previewView];
}
 
        }
 
        [self RTMPush];
 
    } fail:^{
        
    }];
}


3.创建UI界面、基本界面就是美颜控制按钮、各个预设界面、预览界面

- (void)creatUI{
    
    playBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
    playBackView.backgroundColor = [UIColor clearColor];
    playBackView.clipsToBounds = YES;
    [self.view addSubview:playBackView];
    playerMask = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
    playerMask.hidden = YES;
    playerMask.backgroundColor = [UIColor blackColor];
    [playBackView addSubview:playerMask];
   
    _previewView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
    _previewView.backgroundColor = [UIColor clearColor];
    _previewView.clipsToBounds = YES;
    [self.view addSubview:_previewView];
 
    UIButton *_returnBtn = [UIButton buttonWithType:0];
    _returnBtn.frame = CGRectMake(0, 24+statusbarHeight, 40, 40);
    [_returnBtn setImage:[UIImage imageNamed:@"white_backImg"] forState:0];
    [_returnBtn addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
    [_previewView addSubview:_returnBtn];
   
    UIButton *saveBtn = [UIButton buttonWithType:0];
    saveBtn.frame = CGRectMake(_window_width - 55, 24+statusbarHeight, 40, 40);
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:0];
    [saveBtn setTitle:@"保存" forState:0];
    
    [saveBtn addTarget:self action:@selector(bottomButtonClick:) forControlEvents:UIControlEventTouchUpInside];
       [_previewView addSubview:saveBtn];
    saveBtn.tag = 10087;
    
    UIButton *meiyanBtn = [UIButton buttonWithType:0];
    meiyanBtn.frame =CGRectMake(_window_width - 70, 104+statusbarHeight , 60, 60);
    meiyanBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [meiyanBtn setTitleColor:[UIColor whiteColor] forState:0];
    [meiyanBtn setImage:[UIImage imageNamed:@"通话-美颜"] forState:0];
    [meiyanBtn addTarget:self action:@selector(bottomButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    meiyanBtn.tag = 10086;
    [_previewView addSubview:meiyanBtn];
    self.meihuBtn = meiyanBtn;
}


4.当美颜进行调节时会走美颜sdk回调方法,保存相应的数值,上传到服务器,开播时获取服务器数据进行设置、美颜预设功能成功

 
-(void)txsliderValueChange:(UISlider*) obj {
    // todo
    if (obj.tag == 1) { //美颜
        _tx_beauty_level = obj.value;
        [_txLivePublisher setBeautyStyle:0 beautyLevel:_tx_beauty_level whitenessLevel:_tx_whitening_level ruddinessLevel:_redfacDepth];
        // [_txLivePublisher setBeautyFilterDepth:_beauty_level setWhiteningFilterDepth:_whitening_level];
        _whiteValueLb.text = [NSString stringWithFormat:@"%d",(int)obj.value];
 
    } else if (obj.tag == 0) { //美白
        _tx_whitening_level = obj.value;
        [_txLivePublisher setBeautyStyle:0 beautyLevel:_tx_beauty_level whitenessLevel:_tx_whitening_level ruddinessLevel:_redfacDepth];
        _beautyValueLb.text = [NSString stringWithFormat:@"%d",(int)obj.value];
 
        // [_txLivePublisher setBeautyFilterDepth:_beauty_level setWhiteningFilterDepth:_whitening_level];
    } else if (obj.tag == 2) { //大眼
        _tx_eye_level = obj.value;
        [_txLivePublisher setEyeScaleLevel:_tx_eye_level];
    } else if (obj.tag == 3) { //瘦脸
        _tx_face_level = obj.value;
        [_txLivePublisher setFaceScaleLevel:_tx_face_level];
    } else if (obj.tag == 4) {// 背景音乐音量
        [_txLivePublisher setBGMVolume:(obj.value/obj.maximumValue)];
    } else if (obj.tag == 5) { // 麦克风音量
        [_txLivePublisher setMicVolume:(obj.value/obj.maximumValue)];
    }else if (obj.tag == 6){//红润
        _redfacDepth = obj.value;
        [_txLivePublisher setBeautyStyle:0 beautyLevel:_tx_beauty_level whitenessLevel:_tx_whitening_level ruddinessLevel:_redfacDepth];
        _redValueLb.text = [NSString stringWithFormat:@"%d",(int)obj.value];
 
    }
}


5.把对应的数据上传到服务器保存。预设成功

    NSDictionary *dicccc;
    if ([YBToolClass checkNull:[common getTISDKKey]]){
        MYType = @"1";
           dicccc = @{
                @"skin_whiting":@(_tx_whitening_level),
                @"skin_smooth":@(_tx_beauty_level),
                @"skin_tenderness":@(_redfacDepth),
        };
 
    }else{
        MYType = @"2";
           dicccc = @{
                @"skin_whiting":@(_tx_whitening_level),
                @"skin_smooth":@(_tx_beauty_level),
                @"skin_tenderness":@(_redfacDepth),
                @"eye_brow":@(_meimao_level),
                @"big_eye":@(_tx_eye_level),
                @"eye_length":@(_yanju_level),
                @"eye_corner":@(_yanjiao_level),
                @"eye_alat":@(_kaiyanjiao_level),
                @"face_lift":@(_tx_face_level),
                @"face_shave":@(_xiaolian_level),
                @"mouse_lift":@(_mouse_level),
                @"nose_lift":@(_nose_level),
                @"chin_lift":@(_xiaba_level),
                @"forehead_lift":@(_head_level),
                @"lengthen_noseLift":@(_longnose_level),
                @"brightness":@(_light_level),
        };
 
    }
 
    NSString *specsStr =  [self gs_jsonStringCompactFormatForNSArray:dicccc];
     NSLog(@"设置美颜参数--------%@",specsStr);
    [YBToolClass postNetworkWithUrl:@"user.setBeauty" andParameter:@{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"type":MYType,@"preinstall":specsStr} success:^(int code, id  _Nonnull info, NSString * _Nonnull msg) {
        NSLog(@"info---------:%@", info);
        [MBProgressHUD showError:msg];
    } fail:^{
        
    }];

以上就是关于一对一直播系统关于美颜预设功能的相关代码,美颜预设功能的应用能很好的解决主播忘记开美颜的问题,在直播系统短视频系统上,预设功能同样很受欢迎。

声明:以上内容为云豹科技作者本人原创,未经作者本人同意,禁止转载,否则将追究相关法律责任

声明:
以上内容为云豹科技作者本人原创,未经作者本人同意,禁止转载,否则将追究相关法律责任
立即查看