BradLarson / GPUImage2

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
BSD 3-Clause "New" or "Revised" License
4.85k stars 605 forks source link

Filtering a pre-existing video for a set duration and then saving it again #273

Open jwoodrow opened 5 years ago

jwoodrow commented 5 years ago

Hi all,

So I've been trying to add the equivalent of a gif on top of a pre-existing video since last week to no avail (or more like I can do it using AVVideoCompositionCoreAnimationTool but without any hardware acceleration it seems to be time consuming).

So just to set a context:

My solution was to use AVVideoCompositionCoreAnimationTool and simply use CABasicAnimation to animate a sprite sheet of these images and then set it to loop infinitely (or until the layer is destroyed/generating over) and then export it all back.

I've used GPUImage quite extensively now and love using it for all my image filtering needs (live or not), and I knew it could do some video filtering. But I can't seem to find a way to either:

a - apply a filter for a limited time/amount of frames (I define the frame rate of the background video, which is currently at 30fps, myself so I can play around with that if needed). This would probably allow me to change which UIImage/PictureInput/filter is being used and get the expected result

b - apply a filter using a CALayer that would be made dynamic by CABasicAnimation. This might be done if I were to make a fully custom filter type, but I haven't messed around with that part of GPUImage so if that is the solution I would love some pointers because I don't really understand everything going on in the README when it comes to that.

Alternatively if anyone knows how I could use MSL to do this I would be down to learning how to use Metal to this (I've never used Metal myself but I would love to learn how to use it and this might be the perfect occasion to do so). I've looked around but I'm lacking some basic knowledge for this such as how to pass each frame of a video (or the whole video) to Metal, how to load an image as a Metal Texture and then apply it to the corresponding frame and also how to get frame back and then recreate a video in a quicker fashion than AVAssetWriter (maybe ?)

Thanks in advance for any insights you all can give me into this :)