Search code examples
iosiphonecallbackcameragpuimage

GPUImage: is there callback function when a filter is done processing a frame from GPUImageVideoCamera


Basically, I want to grab frames from iPhone camera, input them to a custom filter and get the result from that custom filter into my own CPU memory for further processing. The question is given that camera sends 30 frames to the filter per second, How do I know when a frame is done by that filter? In other words, is there a callback function when the filter is finished processing each frame from the camera? the code is as following:

    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
    MyOwnGPUFilter *mof=[[MyOwnGPUFilter alloc] init];
    [videoCamera addTarget:mof];
    [videoCamera startCameraCapture];

Solution

  • For something like this, I recommend using a GPUImageRawDataOutput class and setting its newFrameAvailableBlock. If you make the GPUImageRawDataOutput the target of your filter, that block will be triggered the instant the filter finishes processing.

    The GPUImageRawDataOutput gives you direct access to the raw color data, and uses the most efficient means it can to pull that down. That should make it easy to pass those color bytes into your CPU-side processing.