美文网首页
GPUImage-本地视频添加滤镜无声音问题

GPUImage-本地视频添加滤镜无声音问题

作者: Th丶小伟 | 来源:发表于2017-12-02 16:54 被阅读0次
    - (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;//加入声音
    
    

    但我发现合成好慢,有没有朋友发现用什么方式会合成得快一些

    相关文章

      网友评论

          本文标题:GPUImage-本地视频添加滤镜无声音问题

          本文链接:https://www.haomeiwen.com/subject/dtgnbxtx.html