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.25k stars 4.61k forks source link

Blending a video with an animated gif #2319

Open nixnoughtnothing opened 8 years ago

nixnoughtnothing commented 8 years ago

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.

BradLarson commented 8 years ago

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

longsangstan commented 8 years ago

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.

porridgec commented 8 years ago

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

longsangstan commented 7 years ago

@porridgec I tried but didn't work

hezhk3 commented 5 years ago

Use AVVideoCompositionCoreAnimationTool to export CAKeyFrameAnimation with keypath contents.

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