使用GPUImage为视频添加水印,捕获诸如“试图过度释放帧缓冲区”的错误

时间:2018-06-29 08:49:38

标签: ios objective-c

这让我感到困惑,因为有时只有在您测试了5-6次之后,它才能出现,但有时您又再测试了1次。这是我的代码:

UIImage *coverImage1 = [UIImage imageNamed:@"imageName"];
UIImageView *coverImageView1 = [[UIImageView alloc] initWithImage:coverImage1];
[coverImageView1 setFrame:CGRectMake(20, size.height-100, 210, 50)];


UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
subView.backgroundColor = [UIColor clearColor];

[subView addSubview:coverImageView1];

GPUImageUIElement *uielement = [[GPUImageUIElement alloc] initWithView:subView];
NSString *pathToMovie =string;
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];

movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(720.0, 1280.0)];

GPUImageFilter* progressFilter = [[GPUImageFilter alloc] init];
[progressFilter addTarget:filter];
[movieFile addTarget:progressFilter];
[uielement addTarget:filter];
movieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = movieWriter;
[filter addTarget:movieWriter];
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[movieFile startProcessing];

__weak typeof(self) weakSelf = self;
[progressFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) {
    [uielement update];
}];
[movieWriter setCompletionBlock:^{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        __strong typeof(self) strongSelf = weakSelf;
        [strongSelf->filter removeTarget:strongSelf->movieWriter];
        [strongSelf->movieWriter finishRecording];
        [uielement useNextFrameForImageCapture];
        //[[GPUImageContext sharedFramebufferCache]purgeAllUnassignedFramebuffers];
        UISaveVideoAtPathToSavedPhotosAlbum(strongSelf->string, strongSelf, @selector(video:didFinishSavingWithError:contextInfo:), nil);
    });
}];

我试图将[uielement useNextFrameForImageCapture];移到[progressFilter setFrameProcessingCompletionBlock...]内,但也没有用

0 个答案:

没有答案