GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Blending a video with an animated gif

Open nixnoughtnothing opened this issue 8 years ago • 5 comments

Hi there!

I use GPUImageVideoCamera with blend filters (e.g. GPUImageDissolveBlendFilter) and it works pretty well with an image but Is there a way to blend an animated gif and a video?

Any advice and suggestions will be greatly appreciated.

nixnoughtnothing avatar Jun 26 '16 07:06 nixnoughtnothing

Currently, there is no support for importing and playing animated GIFs.

BradLarson avatar Jun 27 '16 15:06 BradLarson

I have the same problem as well - would be great if gifs are supported!

Currently I am using a little work around to achieve the animation effect: Manually set the next frame image in the setFrameProcessingCompletionBlock.

Like this:

    self.frameNum = 1;

    __unsafe_unretained GPUImageUIElement *weakUIElementInput = self.element;
    [filter setFrameProcessingCompletionBlock:^(GPUImageOutput *output, CMTime time) {

// set next frame image to fake animation
            [self.animationImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image_%d.png", self.frameNum]]];

            // determine next frame number
            if (self.frameNum == 10){
                self.frameNum = 1;
            } else {
                self.frameNum = self.frameNum + 1;
            }

        [weakUIElementInput update];
    }];

One drawback of this method is that you can't control the speed of animation.

longsangstan avatar Nov 01 '16 00:11 longsangstan

@BradLarson which means the property animationImages of UIImageView is unavailable also?

porridgec avatar Nov 10 '16 09:11 porridgec

@porridgec I tried but didn't work

longsangstan avatar Nov 15 '16 10:11 longsangstan

Use AVVideoCompositionCoreAnimationTool to export CAKeyFrameAnimation with keypath contents.

https://www.raywenderlich.com/2734-avfoundation-tutorial-adding-overlays-and-animations-to-videos

hezhk3 avatar Jan 12 '19 05:01 hezhk3