如何在现有视频中添加过滤器?
How to add filters in Existing video?
我想在我现有的捕获视频中添加滤镜效果,我尝试使用 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
});
}];
}
我想在我现有的捕获视频中添加滤镜效果,我尝试使用 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
});
}];
}