我想在现有的已捕获视频中添加过滤效果,我尝试使用GPUImageMovie(<GPUImage/GPUImage.h>)
进行此操作,但在[movieWriter startRecording];
上遇到崩溃所以如果有其他任何正确方法,请您建议我这样做。
提前致谢。
答案 0 :(得分:0)
只需传递现有的videoURL即可过滤,不要忘记添加GPUImage Framework。
- (void)testFilterOptions:(NSURL*)videoUrl{
movieFile = [[GPUImageMovie alloc] initWithURL:videoUrl];
movieFile.runBenchmark = YES;
movieFile.playAtActualSpeed = NO;
//filter = [[GPUImagePixellateFilter alloc] init];
filter = [[GPUImageSepiaFilter alloc] init];
[movieFile addTarget:filter];
// Only rotate the video for display, leave orientation the same for recording
// GPUImageView *filterView = (GPUImageView *)self.previewView;
// [filter addTarget:filterView];
// In addition to displaying to the screen, write out a processed version of the movie to disk
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mov"];
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];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 480.0)];
[filter addTarget:movieWriter];
// Configure this for video from the movie file, where we want to preserve all video frames and audio samples
movieWriter.shouldPassthroughAudio = NO;
movieFile.audioEncodingTarget = nil;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[movieWriter startRecording];
[movieFile startProcessing];
[movieWriter setCompletionBlock:^{
[filter removeTarget:movieWriter];
[movieWriter finishRecording];
dispatch_async(dispatch_get_main_queue(), ^{
//Recording complete do whatever you want
});
}];
}