我已经浏览了几个新GPUImageUIElementFilter
的示例,并尝试将它们应用于我从磁盘上获得的视频,但我正在获取“白屏”视频。我已尝试使用其他过滤器(sepia,pixelate)运行代码,它似乎工作正常,但与ui元素的混合失败。
这是我的代码:
//Declared in interface
@property(nonatomic, strong) GPUImageMovieWriter *movieWriter;
@property(nonatomic, strong) GPUImageMovie *movieFile;
@property(nonatomic, strong) GPUImageFilter *blendFilter;
@property(nonatomic, strong) GPUImageUIElement *uiElementFilter;
- (void)videoOutputOverlay {
self.movieFile = [[GPUImageMovie alloc] initWithURL:self.post.url];
self.movieFile.runBenchmark = YES;
self.movieFile.playAtActualSpeed = YES;
self.blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
((GPUImageAlphaBlendFilter *)self.blendFilter).mix = 1.0;
self.drawingView.backgroundColor = [UIColor clearColor];
self.uiElementFilter = [[GPUImageUIElement alloc] initWithView:self.drawingView];
[self.movieFile addTarget:self.blendFilter];
[self.uiElementFilter addTarget:self.blendFilter];
// In addition to displaying to the screen, write out a processed version of the movie to disk
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Output.m4v"];
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(640.0, 480.0)];
[self.blendFilter addTarget:self.movieWriter];
// Configure this for video from the movie file, where we want to preserve all video frames and audio samples
self.movieWriter.shouldPassthroughAudio = YES;
self.movieFile.audioEncodingTarget = self.movieWriter;
[self.movieFile enableSynchronizedEncodingUsingMovieWriter:self.movieWriter];
[self.movieWriter startRecording];
[self.movieFile startProcessing];
__weak PostPreviewViewController *weakSelf = self;
[self.movieWriter setCompletionBlock:^{
[weakSelf.blendFilter removeTarget:weakSelf.movieWriter];
[weakSelf.movieWriter finishRecording];
UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, NULL, NULL);
NSLog(@"completed saving movie");
}];
}
这几乎是从网上的一些例子中完全复制的,主要区别在于我使用的文件不是直播视频。
在我的“相机胶卷”中导出的视频中,我可以听到音频+所有与其他滤镜一起使用的内容,因此我确信视频正确加载(加上导出时没有出现任何错误)
我假设我设置过滤器/目标的方式有问题。
非常感谢任何帮助!感谢
答案 0 :(得分:0)
如果有人碰到这个问题,我能够在某种程度上解决它(现在我的情况下只是缺少声音)。这是我的代码,介意它有一些项目特定的东西,但是相当通用,否则
{{1}}