0
我已經通過了新的GPUImageUIElementFilter
的幾個例子了,並試圖將其應用到視頻我從磁盤有,但我得到一個「白屏」視頻代替。我試着用其他過濾器(棕褐色,像素)運行代碼,它似乎工作正常,但與UI元素混合失敗。GPUImageUIElementFilter與白色畫面返回視頻
這裏是我的代碼:
//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");
}];
}
這一切幾乎從一些例子在那裏網上覆制相同,主要區別是,我使用的是文件沒有視頻直播。
在我的「相機膠捲」導出的視頻,我可以聽到音頻+一切都與其它過濾器的工作,所以我相信視頻是正確加載(加上沒有得到對出口的任何錯誤)
我假設我設置過濾器/目標的方式有問題。
將不勝感激任何幫助!由於