- (void)saveVideo {
NSURL *sampleURL =[NSURL fileURLWithPath: [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/1512121874.mp4"]];//视频文件
// 初始化 movie
_imageMovie = [[GPUImageMovie alloc] initWithURL:sampleURL];
_imageMovie.shouldRepeat = NO;
_imageMovie.playAtActualSpeed = YES;
// 设置加滤镜视频保存路径
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mp4"];//输出文件
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
// 初始化
_movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(960,544)];
_movieWriter.encodingLiveVideo = NO;
_movieWriter.shouldPassthroughAudio = YES;//是否使用源音源
_imageMovie.audioEncodingTarget = _movieWriter;//加入声音
// 添加滤镜
GPUImageToonFilter *filter = [[GPUImageToonFilter alloc] init];
[_imageMovie addTarget:filter];
[filter addTarget:_movieWriter];
[_imageMovie enableSynchronizedEncodingUsingMovieWriter:_movieWriter];
[_movieWriter startRecording];
[_imageMovie startProcessing];
__weak typeof(self) weakSelf = self;
[_movieWriter setCompletionBlock:^{
NSLog(@"合并完成");
[filter removeTarget:weakSelf.movieWriter];
[weakSelf.movieWriter finishRecording];
}];
[_movieWriter setFailureBlock:^(NSError *error) {
NSLog(@"合成失败 173:error = %@",error.description);
}];
搞了很久终于发现加入滤镜没有声音是什么问题
_movieWriter.shouldPassthroughAudio = YES;//是否使用源音源
_imageMovie.audioEncodingTarget = _movieWriter;//加入声音
但我发现合成好慢,有没有朋友发现用什么方式会合成得快一些
网友评论