企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
实时音视频的修改也比较多,需要注意的是MHBeautyManager 参数要始终保持一致,也就是传入MHMeiyanMenusView和Zego的滤镜类的参数是一样的。 需要在下面的类中作如下修改。黑框中的部分为新加的,可以与即构的demo对比参考。 ZGVideoFilterAsyncDemo.h ``` @property (nonatomic, strong) MHBeautyManager *beautyManager; ``` ZGVideoFilterAsyncDemo.m ``` // SDK 回调。App 在此接口中获取 SDK 采集到的视频帧数据,并进行处理 - (void)queueInputBuffer:(CVPixelBufferRef)pixel_buffer timestamp:(unsignedlonglong)timestamp_100n { // * 采集到的图像数据通过这个传进来,这个点需要异步处理 dispatch_async(queue_, ^ { int imageWidth = (int)CVPixelBufferGetWidth(pixel_buffer); int imageHeight = (int)CVPixelBufferGetHeight(pixel_buffer); int imageStride = (int)CVPixelBufferGetBytesPerRowOfPlane(pixel_buffer, 0); CVPixelBufferRef dst = [self->buffer_pool_dequeueInputBuffer:imageWidth height:imageHeight stride:imageStride]; ``` ![](https://img.kancloud.cn/19/f2/19f20e81181aba758c676121ca172bd2_1734x504.png) ``` //if (dst) { // if(self.beautyManager){ // [self.beautyManager processZGWithPixelBuffer:pixel_buffer];         //    } CVPixelBufferRef output = pixel_buffer; if ([ZGImageUtilscopyPixelBufferFrom:output to:dst]) {  // * 把从 buffer pool 中得到的 CVPixelBuffer 实例传进来                 [self->buffer_pool_queueInputBuffer:dst timestamp:timestamp_100n];             }         } self.pendingCount= self.pendingCount- 1; CVPixelBufferRelease(pixel_buffer);     }); } ``` lZGVideoFilterAsyncDemo.h ``` @property (nonatomic, strong) MHBeautyManager *beautyManager; ``` lZGVideoFilterFactoryDemo.m ``` // 创建外部滤镜实例 - (id)zego_create { if (g_filter_== nil) {         // 此处的 bufferType 对应四种滤镜类型,以创建不同的外部滤镜实例 switch (self.bufferType) { case ZegoVideoBufferTypeAsyncPixelBuffer:                 { g_filter_ = [[ZGVideoFilterAsyncDemo alloc] init];                     ZGVideoFilterAsyncDemo* g_filter = ///黑框部分开始 (ZGVideoFilterAsyncDemo*)g_filter_; [g_filter setMHBeautyManager:self.beautyManager]; ///黑框部分结束                 } break; case ZegoVideoBufferTypeSyncPixelBuffer: g_filter_ = [[ZGVideoFilterSyncDemo alloc] init]; break; case ZegoVideoBufferTypeAsyncI420PixelBuffer: g_filter_ = [[ZGVideoFilterI420Demo alloc] init]; break; case ZegoVideoBufferTypeAsyncNV12PixelBuffer: g_filter_ = [[ZGVideoFilterNV12Demo alloc] init]; break; default: break;         }     } returng_filter_; } ``` ZGExternalVideoFilterDemo.h 添加如下方法: ``` - (void)initFilterFactoryType:(ZegoVideoBufferType)type beautyManager:(MHBeautyManager*)beautyManager; lZGExternalVideoFilterDemo.m实现该方法: - (void)initFilterFactoryType:(ZegoVideoBufferType)type beautyManager:(MHBeautyManager*)beautyManager{ if (self.g_filterFactory== nil) { self.g_filterFactory = [[ZGVideoFilterFactoryDemo alloc] init]; self.g_filterFactory.bufferType = type; self.g_filterFactory.beautyManager = beautyManager;     } [ZGApiManager releaseApi]; [ZegoExternalVideoFilter setVideoFilterFactory:self.g_filterFactorychannelIndex:ZEGOAPI_CHN_MAIN]; } ``` ZGVideoTalkLoginViewController ``` 初始化MHBeautyManager  - (MHBeautyManager *)beautyManager { if (!_beautyManager) {         _beautyManager = [[MHBeautyManageralloc] init];     } return_beautyManager; } ``` 在ViewDidLoad方法中初始ZGExternalVideoFilterDemo: ``` self.demo = [[ZGExternalVideoFilterDemoalloc] init]; self.demo.delegate= self; [self.demo initFilterFactoryType:ZegoVideoBufferTypeAsyncPixelBuffer beautyManager:self.beautyManager]; ``` ZGVideoTalkViewController是实现视频通话的功能,将上一步中的beautyManager作为参数传入。 ``` ZGVideoTalkViewController*vc = [sb instantiateViewControllerWithIdentifier:NSStringFromClass([ZGVideoTalkViewControllerclass])];     vc.roomID = roomID; vc.videoTalkDemo= self.videoTalkDemo; vc.beautyManager= self.beautyManager; ``` 在ZGVideoTalkViewController.h文件中 ``` @property (nonatomic, strong) MHBeautyManager *beautyManager; ``` ZGVideoTalkViewController .m 文件中对美颜UI初始化,并将传入的beautyManager传入MHMeiyanMenusView ``` - (MHMeiyanMenusView *)menusView { if (!_menusView) {         _menusView = [[MHMeiyanMenusView alloc] initWithFrame:CGRectMake(0, window_height- MHMeiyanMenuHeight- BottomIndicatorHeight, window_width, MHMeiyanMenuHeight) superView:self.viewdelegate:self  beautyManager:self.beautyManagerisTXSDK:NO];     } return _menusView; } ```