【问题标题】:Multiple time allocation of GPUImageFilter crashes the applicationGPUImageFilter 的多次分配时间使应用程序崩溃
【发布时间】:2013-10-21 13:48:12
【问题描述】:

我正在做一个图片/视频滤镜效果项目。为了产生效果,我正在使用 GPUImage 项目。它适用于图片。现在我也需要对视频做同样的效果。我以每秒 30 帧的速度从视频中抓取图像。现在对于 1 分钟的视频,我过滤了大约 1800 张图像。和过滤,我为每个图像分配 GPUImagePicture 和 GPUImageSepiaFilter 类,并手动释放它们。但是这些分配并没有被释放,并且在处理大约 20 秒后,视频应用程序由于内存警告而崩溃。 是否可以一次分配 GPUImagePicture 和 Filter 类来对所有图像进行过滤。如果是,如何? 请告诉我这将非常有帮助。 这是我的代码,我正在做什么......

get image方法由NSTimer调用,每秒调用30次,从app文档目录中获取图片并发送到-(void)imageWithEffect:(UIImage *)image方法进行过滤。

-(void)getImage
{
    float currentPlayBacktime =  slider.value;
    int frames = currentPlayBacktime*30;
    NSString *str = [NSString stringWithFormat:@"image%i.jpg",frames+1];

    NSString *fileName = [self.imgFolderPath stringByAppendingString:str];
    if ([fileManager fileExistsAtPath:fileName])
        [self imageWithEffect:[UIImage imageWithContentsOfFile:fileName]];


}


- (void)imageWithEffect:(UIImage *)image
{


        GPUImagePicture *gpuPicture = [[GPUImagePicture alloc]initWithImage:img] ;
        GPUImageSepiaFilter *filter = [[[GPUImageSepiaFilter alloc]init] autorelease];
         gpuPicture = [gpuPicture initWithImage:image];
        [gpuPicture addTarget:filter];
        [gpuPicture processImage];

        playerImgView.image = [filter imageFromCurrentlyProcessedOutputWithOrientation:0];

        [gpuPicture removeAllTargets];

        [filter release];
        [gpuPicture release];

}

【问题讨论】:

    标签: iphone ios objective-c gpuimage


    【解决方案1】:

    为什么要将电影处理为一系列静止的 UIImage?为什么要为每个图像分配一个新的过滤器?这将非常缓慢。

    相反,如果您需要处理电影文件,请使用 GPUImageMovie 输入,如果您需要访问相机,请使用 GPUImageVideoCamera 输入。两者都经过调整以通过过滤器管道提供快速的视频馈送。在静态帧与 UIImage 之间的转换过程中浪费了大量的处理周期。

    另外,只设置一次过滤器,并在必要时重复使用。创建 GPUImageFilter(设置 FBO 等)会产生大量开销,因此您只需创建一次,然后在输入和输出更改时附加它们。

    【讨论】:

    • 感谢布拉德的建议。但我正在处理静止图像,因为在我的要求中,我不需要对完整的视频进行过滤,比如前 10 秒的 1 分钟视频效果,然后是 25-30 秒,然后是 40-50 秒。所以我正在处理静止图像。
    • 为什么不使用 Brad 建议的 GPUImageMovie 或 GPUImageVideoCamera 类,将过滤器放入 GPUImagePipeline,然后在 10 秒、25 秒、30 秒等时在过滤器数组之间切换......这将正如 Brad 所描述的那样,通过过滤/未过滤之间的无缝转换和许多数量级的性能更好地实现您所描述的。
    • [_pipeline replaceAllFilters:filters] 其中 _pipeline 是 GPUImageFilterPipeline 的一个实例
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多