Search code examples
iosobjective-cxcode5gpuimage

Basic GPUImage iOS7 app video freezes / not working


I am new to GPUImage and I added GPUImage to a Default Single-View template Xcode 5.1.1 app. I successfully the static GPUImage library and I am trying the example from Readme file. I have iO S7.1 as base SDK. The app compiles and loads and the video just freezes. It freezes with or without the Filter. How do I fix this? I want to display live camera preview with a filter applied to it

The examples included in github repo compile and run fine.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset352x288 cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    GPUImageFilter *customFilter = [[GPUImageSepiaFilter alloc]init];
    GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 320)];
    [self.view addSubview:filteredVideoView];
    // Add the view somewhere so it's visible


    [videoCamera addTarget:customFilter];
    [customFilter addTarget:filteredVideoView];

    [videoCamera startCameraCapture];
}

Here is the screen capture from my iPhone 5 running iOS 7.1.

camera with frozen video


Solution

  • It's freezing because your GPUImageVideoCamera is being deallocated. You're creating it as a local variable, not an instance variable or property, so as soon as your setup method finishes, ARC will deallocate it. This will tear down the rest of your image processing pipeline.

    You need to make your GPUImageVideoCamera instance a property on your class or an instance variable in order to have a strong reference to it beyond your setup method. The camera needs to persist beyond that method, so you need to make sure it does. The camera will hold a strong reference to anything downstream of it, so you don't need to do the same for your filters, unless you want to adjust them at some point.