0
我想在我现有的捕获的视频中添加滤镜效果,我试图用GPUImageMovie(<GPUImage/GPUImage.h>)
来做到这一点,但碰到[movieWriter startRecording];
,所以如果有任何其他适当的方式来做到这一点,请你给我建议。如何在现有视频中添加过滤器?
在此先感谢。
我想在我现有的捕获的视频中添加滤镜效果,我试图用GPUImageMovie(<GPUImage/GPUImage.h>)
来做到这一点,但碰到[movieWriter startRecording];
,所以如果有任何其他适当的方式来做到这一点,请你给我建议。如何在现有视频中添加过滤器?
在此先感谢。
只要通过您现有的videoURL,它将被过滤,不要忘记添加GPUImage框架。
- (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
});
}];
}