I am using GPUImage for applying video filters. But before applying filter to particular video, I am showing filter previews on the thumbnail image of video at bottom on UIScrollView. For this, I am using imageByFilteringImage: method of filter and I thought it causes memory pressure and crashes application. Please check my code below and suggest necessary changes :
// Get the thumnail image form video
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:self.movieURL options:nil];
AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
imageGenerator.appliesPreferredTrackTransform = true;
UIImage *thumbailImage = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]];
CGFloat xLocation = 10;
for (NSNumber *filterNumber in videoFilterList) {
NSLog(@"filterNumber : %@",filterNumber);
UILabel *filterNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(xLocation, 12, 50, 16)];
filterNameLabel.backgroundColor = [UIColor clearColor];
filterNameLabel.textAlignment = NSTextAlignmentCenter;
filterNameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
UIImage *quickFilteredImage = thumbailImage;
switch (tag) {
case GPUIMAGE_SATURATION:
{
filter = nil;
filter = [[GPUImageSaturationFilter alloc] init];
[(GPUImageSaturationFilter *)filter setSaturation:0.0];
quickFilteredImage = [filter imageByFilteringImage:thumbailImage];
filterNameLabel.text = @"B&W";
} break;
case GPUIMAGE_SEPIA:
{
filter = nil;
filter = [[GPUImageSepiaFilter alloc] init];
quickFilteredImage = [filter imageByFilteringImage:thumbailImage];
filterNameLabel.text = @"Sepia";
} break;
case GPUIMAGE_GRAYSCALE:
{
filter = nil;
filter = [[GPUImageGrayscaleFilter alloc] init];
quickFilteredImage = [filter imageByFilteringImage:thumbailImage];
filterNameLabel.text = @"GrayScale"; break;
}
}
[self.previewFiltersScrollView addSubview:filterNameLabel];
UIImageView *previewFilterImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xLocation, -40, 50, 50)];
previewFilterImageView.userInteractionEnabled = YES;
previewFilterImageView.tag = tag;
previewFilterImageView.contentMode = UIViewContentModeScaleAspectFit;
previewFilterImageView.image = quickFilteredImage;
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(applyFilter:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
tapGestureRecognizer.numberOfTouchesRequired = 1;
[previewFilterImageView addGestureRecognizer:tapGestureRecognizer];
[self.previewFiltersScrollView addSubview:previewFilterImageView];
tag++;
xLocation += 60;
}