BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.24k stars 4.61k forks source link

How to quickly generate the watermark With GPUImageUIElement #2343

Open lengqingfeng opened 8 years ago

lengqingfeng commented 8 years ago

10 second video need about 8 scecod

_elementInput = nil;
_elementInput = [[GPUImageUIElement alloc] initWithView:fView];

_blendFilter = nil;
_blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
_blendFilter.mix = 1.0f;

 [_bfilter addTarget:_blendFilter];
[_elementInput addTarget:_blendFilter];

__weak GPUImageUIElement *weakElement = _elementInput;
[_bfilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime time) {
        [weakElement update];
}];

if (_movieWriter) {
    _movieWriter = nil;
}
_movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:tempVideo size:currenVideoSize];

[_movieFile addTarget:_bfilter];
[_blendFilter addTarget:_movieWriter];

_movieWriter.shouldPassthroughAudio = YES;
_movieFile.audioEncodingTarget = _movieWriter;
[_movieFile enableSynchronizedEncodingUsingMovieWriter:_movieWriter];

[_movieWriter startRecording];
[_movieFile startProcessing];

__weak __typeof(&*self)weakSelf = self;
// 7. Filter effect finished
[weakSelf.movieWriter setCompletionBlock:^{
__strong __typeof(weakSelf)strongSelf = weakSelf;
    [_elementInput removeAllTargets];
    [_blendFilter removeTarget:strongSelf.movieWriter];

    dispatch_async(dispatch_get_main_queue(), ^{
        if ([strongSelf.delegate respondsToSelector:@selector(didFinishVideoDeal: addFilterType:)]) {
            [strongSelf.delegate didFinishVideoDeal:tempVideo addFilterType:fileType];
        }
    });

}];