BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.23k stars 4.61k forks source link

Device specific crash #2330

Open deftsofttester123 opened 8 years ago

deftsofttester123 commented 8 years ago

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];
                        }
                    }];
                }
            }];

}