iOS 云信视频通话 +滤镜效果

云信SDK会把采集数据 回调出来

NIMNetCallVideoCaptureParam *param = [[NIMNetCallVideoCaptureParamalloc]init];

    param.videoHandler = ^(CMSampleBufferRef _Nonnull sampleBuffer) {

//1- 添加回调


    };

    [selffillVideoCaptureSetting:param];

    option.videoCaptureParam = param;


扫描二维码关注公众号,回复: 2388575 查看本文章

//以上回调 添加以下方法

- (void)processVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer

{

    CVPixelBufferRef pixelBuffer =CMSampleBufferGetImageBuffer(sampleBuffer);

    

    size_t bufferWidth = 0;

    size_t bufferHeight = 0;

    

    if (CVPixelBufferIsPlanar(pixelBuffer)) {

        bufferHeight = CVPixelBufferGetHeightOfPlane(pixelBuffer,0);

        bufferWidth = CVPixelBufferGetWidthOfPlane(pixelBuffer,0);

    } else {

        bufferWidth = CVPixelBufferGetWidth(pixelBuffer);

        bufferHeight = CVPixelBufferGetHeight(pixelBuffer);

    }


//加滤镜代码  测试

CFAbsoluteTime elapsedTime, startTime =CFAbsoluteTimeGetCurrent();

        CIImage *inputImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];

        

        // 创建滤镜

        CIFilter *fiter = [CIFilter filterWithName:@"CIPhotoEffectInstant"];

        

        [fiter setValue:inputImage forKey:@"inputImage"];

        CIImage *outputImage = [fiter outputImage];

        elapsedTime = CFAbsoluteTimeGetCurrent() - startTime;

        NSLog(@"Core Image frame time: %f", elapsedTime *1000.0);

        

        EAGLContext *openglCtx = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES2];

        CIContext *ctx = [CIContext contextWithEAGLContext:openglCtx];

        [ctx render:outputImage toCVPixelBuffer:pixelBuffer];


// 处理完的数据 塞回云信

    [[NIMAVChatSDKsharedSDK].netCallManagersendVideoSampleBuffer:sampleBuffer];

}



猜你喜欢

转载自blog.csdn.net/idlehand/article/details/78933584
今日推荐