在基本项目中使用GPUImage实时视频过滤器以纯白屏幕结果

时间:2014-05-09 02:39:35

标签: ios gpuimage

我刚刚将GPUImage集成到一个全新的项目中,并根据Github页面中的说明添加了所需的库。我已将strong属性设为GPUImageVideoCamera,而在viewDidLoad中,我将其实例化为:

self.videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];

修改:项目中的完整代码:

@interface ViewController () <GPUImageVideoCameraDelegate>
{
    GPUImageVideoCamera *videoCamera;
}

@end

@implementation ViewController

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

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    GPUImagePixellatePositionFilter *customFilter = [[GPUImagePixellatePositionFilter alloc] init];
    GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];

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

    [videoCamera startCameraCapture];
}

@end

但是,我得到的只是一个没有任何错误或警告的白色屏幕,并且想知道我做错了什么......谢谢!

1 个答案:

答案 0 :(得分:1)

我知道这是一个老问题,但我遇到了同样的问题并找到了解决办法。它似乎真的很愚蠢,但对我来说,我只是将videoCamera作为一个属性,它开始工作,即:

@interface ViewController ()

@property (nonatomic, strong) GPUImageVideoCamera *camera;

@end

-(void)viewDidLoad {
    [super viewDidLoad];
    self.camera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];

    //etc.
}