pixthecoder pixthecoder - 4 months ago 34
iOS Question

Convert video to animated GIF on iOS

I want to convert a video file taken with the camera (.mp4) and convert it to an animated GIF image.

I looked up the Apple Docs and there doesn't seem to be any built-in function for this.

How should I approach this task?


There is no built-in API for that. I released a library that converts video files to animated GIF images while giving enough flexibility to tweak settings such as frame rate, frame duration, size, etc.

The library is called NSGIF. You can find it here: http://github.com/NSRare/NSGIF

This is the simplest way to convert a video to a GIF:

[NSGIF optimalGIFfromURL:url loopCount:0 completion:^(NSURL *GifURL) {
    NSLog(@"Finished generating GIF: %@", GifURL);

Using the optimalGIFfromURL method, automatically generates the GIF based on the optimal settings. There is also room for way more flexibility. Check out the repo for more samples.