Applying CIFilter to videos in iOS

I am working on a video conferencing application, and the following code sequentially draws a frame on the screen:

 -(int)drawFrameOnMainThread{
    if(mBitmapContext){
        if(mDisplay){
            CGImageRef imageRef = CGBitmapContextCreateImage(mBitmapContext);
    #if TARGET_OS_IPHONE
            UIImage *image = [UIImage imageWithCGImage:imageRef];

            [self performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];

    #elif TARGET_OS_MAC
            [mDisplay setCurrentImage:imageRef];
    #endif
            CGImageRelease(imageRef);
        }
    }
    return 0;
}

I want to apply CIFilter to the frame that is being drawn, so I change the section of iOS code as follows:

UIImage *image = [UIImage imageWithCGImage:imageRef];

        CIImage *beginImage = image.CIImage;

        CIContext *context = [CIContext contextWithOptions:nil];

        CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone" 
                                      keysAndValues: kCIInputImageKey, beginImage, 
                            @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
        CIImage *outputImage = [filter outputImage];

        CGImageRef cgimg = 
        [context createCGImage:outputImage fromRect:[outputImage extent]];
        UIImage *newImg = [UIImage imageWithCGImage:cgimg];

[self performSelectorOnMainThread:@selector(setImage:) withObject:newImg waitUntilDone:YES];

As a result, my video screen will remain black. Can anyone see the error here? I have been on this for several hours and cannot understand it.

+3
source share
1 answer

I fixed this problem, the problem was initializing CIImage in the line:

//Wrong

CIImage *beginImage = image.CIImage;

//Right
CIImage *beginImage = [CIImage imageWithCGImage:imageRef];

As Brad said, performance is unacceptable. The video is about 5 seconds behind the sound on the iPad2. Therefore, I will consider other solutions for this, but I was still glad to see that it works as something more than a proof of concept than anything else.

+4

All Articles