Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device specific crash #2330

Open
deftsofttester123 opened this issue Jul 20, 2016 · 0 comments
Open

Device specific crash #2330

deftsofttester123 opened this issue Jul 20, 2016 · 0 comments

Comments

@deftsofttester123
Copy link

deftsofttester123 commented Jul 20, 2016

App got crashed when trying to implement GPU video filter (GPUImageGrayscaleFilter, GPUImageMissEtikateFilter, GPUImageSepiaFilter etc) in multiple videos. I am using a method which is calling recursively from completion block. And it get crashed during implementation of GPU filter in between of any video and gives the message "Received memory warning.

CODE:
-(void)implementGPU_EffectOnVid:(int)effectToApply noOfSong:(int)songNo{
//getting asset for managing sound of the asset
AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[self.arrSongsForAddingEffects objectAtIndex:songNo] valueForKey:@"assetGalleryURL"]]] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]];
//VIDEO TRACK
NSArray *tracks = [videoAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *videoTrack = [tracks objectAtIndex:0];
CGAffineTransform videoTransform = videoTrack.preferredTransform;
//adding GPU filter in video
movieFile = [[GPUImageMovie alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[self.arrSongsForAddingEffects objectAtIndex:songNo] valueForKey:@"assetGalleryURL"]]]];
filterForVideo = [[GPUImageSepiaFilter alloc] init];
[movieFile addTarget:filterForVideo];
//generate the random number.
int randNum = rand() % (1000 - 1) + 1;
//store merged video is in temprary directory
NSString *pathToMovie = NSTemporaryDirectory();
unlink([pathToMovie UTF8String]);
NSString *completePathToMovie = [pathToMovie stringByAppendingPathComponent:[NSString stringWithFormat:@"GPU_Video%d.mp4",randNum]];
NSURL *movieURL = [NSURL fileURLWithPath:completePathToMovie];
NSLog(@"value of path %@",pathToMovie);
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(videoTrack.naturalSize.width,videoTrack.naturalSize.height)];
[filterForVideo addTarget:movieWriter];
movieWriter.transform = videoTransform;
movieWriter.shouldPassthroughAudio = YES;
//condition for managing check whether the video consist audio or not
if ([[videoAsset tracksWithMediaType:AVMediaTypeAudio] count] > 0) {
movieFile.audioEncodingTarget = movieWriter;
NSLog(@"audio present");
} else{ //no audio
movieFile.audioEncodingTarget = nil;
NSLog(@"no audio");
}
//method implementing gpu filter in video
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[movieFile startProcessing];
//block for completion of implementing filters
__block BOOL completeRec = NO;
__unsafe_unretained typeof(self) weakSelf = self;
__block int effectToApplyInVideo = noOfEffect;
[movieWriter setCompletionBlock:^{
[weakSelf->filterForVideo removeTarget:weakSelf->movieWriter];
[weakSelf->movieWriter finishRecording];
if (!completeRec) {
completeRec = YES;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[[GPUImageContext sharedFramebufferCache] purgeAllUnassignedFramebuffers];

                        //when last video implemented video filter
                        if (songNo == self.arrSongsForAddingEffects.count -1)  {
                            [weakSelf hideActivityIndicator];
                            [weakSelf navigateView];
                        } else{
                            //increasing varible for getting next song
                            noOfSongForApplyingFilter++;
                         //calling this method for implementing GPU Effect in next song
                            [weakSelf implementGPU_EffectOnVid:effectToApplyInVideo noOfSong:noOfSongForApplyingFilter];
                        }
                    }];
                }
            }];

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant