gpt4 book ai didi

iphone - GPUImageFilter 的多次分配导致应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 03:33:22 25 4
gpt4 key购买 nike

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

获取图像方法由 NSTimer 调用,每秒调用 30 次,从应用程序文档目录中获取图像并发送到 - (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];

}

最佳答案

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

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

此外,只需设置一次过滤器,并在必要时重复使用。创建 GPUImageFilter(设置 FBO 等)的开销很大,因此您只想创建它一次,然后在输入和输出发生变化时附加它们。

关于iphone - GPUImageFilter 的多次分配导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19496358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com