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.21k stars 4.61k forks source link

Terminated due to memory issue #2550

Open Neil20170220 opened 6 years ago

Neil20170220 commented 6 years ago

I try to export video with GPUImageColorInvertFilter for infinite times, momery occupy by Other processes increase continuously, and the App is killed finally.

I test use iPhone 8, iOS 11.2.1, Xcode 9.2.

Here is my code:

- (void)export {
    self.index++;

    NSLog(@"------ loop %lu begin ------", self.index);

    NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"Video-20171220-121803" withExtension:@"MP4"];

    self.movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];
    self.filter = [[GPUImageColorInvertFilter alloc] init];

    [self.movieFile addTarget:self.filter];

    NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSDate *now = [[NSDate alloc] init];
    NSString *pathToMovie = [NSString stringWithFormat:@"%@/%@.mp4", documentsPath, now];

    NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];

    self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(3280, 2460)];
    [self.filter addTarget:self.movieWriter];

    self.movieWriter.shouldPassthroughAudio = YES;
    self.movieFile.audioEncodingTarget = self.movieWriter;
    [self.movieFile enableSynchronizedEncodingUsingMovieWriter:self.movieWriter];

    [self.movieWriter startRecording];
    [self.movieFile startProcessing];

    __weak typeof(self) weakSelf = self;
    [self.movieWriter setCompletionBlock:^{
        [weakSelf.movieWriter finishRecordingWithCompletionHandler:^{
            [weakSelf.movieFile endProcessing];
            [weakSelf.movieWriter endProcessing];

            [weakSelf.movieFile removeAllTargets];
            [weakSelf.filter removeAllTargets];

//            [weakSelf.movieWriter.movieWriterContext.framebufferCache purgeAllUnassignedFramebuffers];
//            [[GPUImageContext sharedFramebufferCache] purgeAllUnassignedFramebuffers];

            weakSelf.movieFile = nil;
            weakSelf.movieWriter = nil;
            weakSelf.filter = nil;

            NSLog(@"------ loop %lu end ------", weakSelf.index);

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [weakSelf export];
            });
        }];
    }];
}

Console log:

2017-12-21 10:56:24.201511+0800 TestGPUImage[5681:507472] [DYMTLInitPlatform] platform initialization successful
2017-12-21 10:56:24.424024+0800 TestGPUImage[5681:507322] ------ loop 1 begin ------
2017-12-21 10:56:24.472424+0800 TestGPUImage[5681:507322] Metal GPU Frame Capture Enabled
2017-12-21 10:56:24.473832+0800 TestGPUImage[5681:507322] Metal API Validation Enabled
2017-12-21 10:56:36.244905+0800 TestGPUImage[5681:507462] ------ loop 1 end ------
2017-12-21 10:56:37.345201+0800 TestGPUImage[5681:507322] ------ loop 2 begin ------
2017-12-21 10:56:48.757717+0800 TestGPUImage[5681:507494] ------ loop 2 end ------
2017-12-21 10:56:49.855167+0800 TestGPUImage[5681:507322] ------ loop 3 begin ------
2017-12-21 10:57:01.295918+0800 TestGPUImage[5681:507504] ------ loop 3 end ------
2017-12-21 10:57:02.395126+0800 TestGPUImage[5681:507322] ------ loop 4 begin ------
2017-12-21 10:57:13.619635+0800 TestGPUImage[5681:507462] ------ loop 4 end ------
2017-12-21 10:57:14.715098+0800 TestGPUImage[5681:507322] ------ loop 5 begin ------
2017-12-21 10:57:26.126941+0800 TestGPUImage[5681:507494] ------ loop 5 end ------
2017-12-21 10:57:27.225068+0800 TestGPUImage[5681:507322] ------ loop 6 begin ------
2017-12-21 10:57:38.677026+0800 TestGPUImage[5681:507494] ------ loop 6 end ------
2017-12-21 10:57:39.777085+0800 TestGPUImage[5681:507322] ------ loop 7 begin ------
2017-12-21 10:57:51.205614+0800 TestGPUImage[5681:507462] ------ loop 7 end ------
2017-12-21 10:57:52.304992+0800 TestGPUImage[5681:507322] ------ loop 8 begin ------
2017-12-21 10:58:03.683542+0800 TestGPUImage[5681:507553] ------ loop 8 end ------
2017-12-21 10:58:04.777104+0800 TestGPUImage[5681:507322] ------ loop 9 begin ------
2017-12-21 10:58:16.195421+0800 TestGPUImage[5681:507553] ------ loop 9 end ------
2017-12-21 10:58:17.294912+0800 TestGPUImage[5681:507322] ------ loop 10 begin ------
2017-12-21 10:58:28.737305+0800 TestGPUImage[5681:507938] ------ loop 10 end ------
2017-12-21 10:58:29.837053+0800 TestGPUImage[5681:507322] ------ loop 11 begin ------
2017-12-21 10:58:41.274280+0800 TestGPUImage[5681:507504] ------ loop 11 end ------
2017-12-21 10:58:42.370562+0800 TestGPUImage[5681:507322] ------ loop 12 begin ------
2017-12-21 10:58:53.802709+0800 TestGPUImage[5681:507494] ------ loop 12 end ------
2017-12-21 10:58:54.894791+0800 TestGPUImage[5681:507322] ------ loop 13 begin ------
2017-12-21 10:59:06.392834+0800 TestGPUImage[5681:507553] ------ loop 13 end ------
2017-12-21 10:59:07.488873+0800 TestGPUImage[5681:507322] ------ loop 14 begin ------
2017-12-21 10:59:19.582711+0800 TestGPUImage[5681:507553] ------ loop 14 end ------
2017-12-21 10:59:20.674655+0800 TestGPUImage[5681:507322] ------ loop 15 begin ------
2017-12-21 10:59:32.168117+0800 TestGPUImage[5681:507494] ------ loop 15 end ------
2017-12-21 10:59:33.264523+0800 TestGPUImage[5681:507322] ------ loop 16 begin ------
2017-12-21 10:59:44.743873+0800 TestGPUImage[5681:507504] ------ loop 16 end ------
2017-12-21 10:59:45.838880+0800 TestGPUImage[5681:507322] ------ loop 17 begin ------
2017-12-21 10:59:57.344725+0800 TestGPUImage[5681:507462] ------ loop 17 end ------
2017-12-21 10:59:58.444451+0800 TestGPUImage[5681:507322] ------ loop 18 begin ------
2017-12-21 11:00:09.973719+0800 TestGPUImage[5681:508769] ------ loop 18 end ------
2017-12-21 11:00:11.067642+0800 TestGPUImage[5681:507322] ------ loop 19 begin ------
2017-12-21 11:00:22.619509+0800 TestGPUImage[5681:507553] ------ loop 19 end ------
2017-12-21 11:00:23.714545+0800 TestGPUImage[5681:507322] ------ loop 20 begin ------
2017-12-21 11:00:35.369409+0800 TestGPUImage[5681:508769] ------ loop 20 end ------
2017-12-21 11:00:36.464379+0800 TestGPUImage[5681:507322] ------ loop 21 begin ------
Message from debugger: Terminated due to memory issue

dingtalk20171221110012

Can any one help? thanks!

Nycojie commented 6 years ago

I also happend to this problem,i using GPUImageScreenBlendFilter ,export the video successfully,but then the app killed,xcode get the same error with you .

Neil20170220 commented 6 years ago

@Nycojie after search and search, i find https://github.com/BradLarson/GPUImage/pull/2549 fix this issue!

Nycojie commented 6 years ago

@Neil20170223 ,i try it ,but it does't work/(ㄒoㄒ)/~~ i add some code to my program,let the two movieFile remove all the targets,then the app not crash.Before i use two movieFile and not add 'remove all the targets', it work well too.

Neil20170220 commented 6 years ago

@Nycojie 不清楚你的流程是什么样的, 你也是做压力测试?

sagarkoyani commented 5 years ago

I am trying to add green screen effect on the video for that i am using gpuimagechromakey Filter. It is crashing after 2-3 seconds and give message from debugger Message from debugger: Terminated due to memory issue.

Nycojie commented 5 years ago

@sagarkoyani
Merge the two videos together? Or green screen video as a video filter?

sagarkoyani commented 5 years ago

@Nycojie green screen video as a video filter