如何在模糊视频上获取GPUImageUIElement而不模糊元素本身

时间:2015-07-18 14:56:05

标签: ios gpuimage movie

我有一个视频,我想在视频的最后添加一个水印。要求是模糊最后一秒,并在视频上放置GPUImageUIElement。这就是我想要的:

enter image description here

但事实证明是这样的:

enter image description here

我只想模糊电影,而不是标签。

这是我的过程:

self.originMovie = [[GPUImageMovie alloc] initWithAsset:video];

self.regularFilter = [[GPUImageFilter alloc] init];

self.blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
self.blendFilter.mix = 1.0;

self.combinationViewElement = [[GPUImageUIElement alloc] initWithView:self.combinationView];


self.regularFilter.frameProcessingCompletionBlock = ^(GPUImageOutput *output, CMTime time){
    [weakSelf updateCombinationWithTimestamp:time];
    [weakSelf.combinationViewElement update];

};




AVAssetTrack *videoTrack = [[video tracksWithMediaType:AVMediaTypeVideo] firstObject];

GPUImageUIElement *watermarkElement = [[GPUImageUIElement alloc] initWithView:self.watermarkView];

self.watermarkBlurFilter = [[GPUImageGaussianBlurPositionFilter alloc] init];
self.watermarkBlurFilter.blurSize = 0;

GPUImageFilter *filter = [[GPUImageFilter alloc] init];
filter.frameProcessingCompletionBlock = ^(GPUImageOutput *output , CMTime time) {
    if (isnan(weakSelf.originMovie.progress)) {
        return;
    }

    CGFloat duration = CMTimeGetSeconds(weakSelf.originMovie.asset.duration);
    if ([weakSelf isWithinWatermarkDuration]) {
        // 从最后一秒开始,blurSize从0线性递增到3
        weakSelf.watermarkBlurFilter.blurSize = ((weakSelf.originMovie.progress * duration ) + (1 - duration)) * 3;

        weakSelf.watermarkView.hidden = NO;
    }

    [watermarkElement update];

    if (weakSelf.progressHandler) {
        dispatch_async(dispatch_get_main_queue(), ^{
            weakSelf.progressHandler(weakSelf.originMovie.progress);
        });

    }
};

GPUImageAlphaBlendFilter *watermarkBlendFilter = [[GPUImageAlphaBlendFilter alloc] init];
watermarkBlendFilter.mix = 1.0;


self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:self.videoURL size:videoTrack.naturalSize];
self.movieWriter.shouldPassthroughAudio = YES;

self.originMovie.audioEncodingTarget = self.movieWriter;
[self.originMovie enableSynchronizedEncodingUsingMovieWriter:self.movieWriter];


[self.originMovie addTarget:self.regularFilter];

[self.regularFilter addTarget:self.blendFilter];
[self.combinationViewElement addTarget:self.blendFilter];

[self.blendFilter addTarget:self.watermarkBlurFilter];

[self.watermarkBlurFilter addTarget:filter];

[filter addTarget:watermarkBlendFilter];
[watermarkElement addTarget:watermarkBlendFilter];

[watermarkBlendFilter addTarget:self.movieWriter];


[self.movieWriter startRecording];
[self.originMovie startProcessing];

combinationViewElement是我的另一个进程,与此问题无关。 我不知道我是否犯了错误,所以任何人都有任何想法,请让我知道,欣赏它。

1 个答案:

答案 0 :(得分:0)

那是因为您在混合之后添加了模糊滤镜,您可以在输入影片上压印UI元素。您需要移动模糊过滤器,使其在self.regularFilter之后移动,但在此之前输入self.blendFilter

混合后的模糊只会模糊整个混合图像。