Search code examples
iosvideo-capturegpuimageimage-capture

ios xcode GPUimage video recording and still image capture


The app I am working on allows the user to record video with the selected effect. It is based on the GPUIamge FilterShowcase example.

I have just added the option to capture a still image of the current video effect that is selected.

Capturing the still image works but is very slow. There is a long delay ( 1 to 2 seconds ) from the time that the capture still image method is called and the time that the image is actually saved.

Is there a more optimized method to achieve this?

Thank you.

Code follows:

-(IBAction)savePhotoWithEffects:(id)sender
{

    // disable buttons - prevent user 
    btnPhoto.enabled=NO;
    btnRecord.enabled=NO;

    // stop videoCamera capture
    [videoCamera stopCameraCapture];

    [stillCamera capturePhotoAsImageProcessedUpToFilter:filter withCompletionHandler:^(UIImage *captureImage, NSError *error){

        if (error) {
            NSLog(@"ERROR: Could not capture!");
        }
        else {
            // save file

            NSLog(@"PHOTO SAVED - ??");

            // save photo to album
            UIImageWriteToSavedPhotosAlbum(captureImage, nil, nil, nil);
        }

        runOnMainQueueWithoutDeadlocking(^{

                 // Start video camera capture again
                 [videoCamera startCameraCapture];

                  // enable the take photo and start recording buttons again
                 btnPhoto.enabled=YES;
                 btnRecord.enabled=YES;

             });

    }];

}

Solution

  • If I had to guess I would say that the delay comes from trying to run a GPUImageStillCamera and a GPUImageVideoCamera simultaneously. You could try doing something like this:

    [videoCamera pauseCameraCapture];
    UIImage *capturedImage = [filter imageFromCurrentlyProcessedOutput];
    UIImageWriteToSavedPhotosAlbum(capturedImage, nil, nil, nil);
    [videoCamera resumeCameraCapture];
    

    That way you don't need a GPUImageStillCamera at all. Hopefully that helps!