Giter Club home page Giter Club logo

nsgif's Introduction

NSGIF

NSGIF is an iOS Library for converting your videos into beautiful animated GIFs. Check out this example.

Sometimes we need to deal with GIFs in Cocoa. This can really be a pain in the ass (believe me). And here comes our hero :octocat:. Breaking through errors and glitches and generating smooth GIFs 💨.

How it works

NSGIF That's it really. Although iOS defaults to .MOV for recordings you can also use .AVI and .MP4. If you want to go into some technical details though, here they are:

Add to your project

There are 2 ways you can add NSGIF to your project:

Manual installation

Simply import the 'NSGIF' into your project then import the following in the class you want to use it:

#import "NSGIF.h"

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like NSGIF in your projects. See the "Getting Started" guide for more information.

Podfile

platform :ios, '7.0'
pod "NSGIF", "~> 1.0"

Practical use

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

This generates a GIF from the provided video, by automatically setting the best frame count, delay time and size.

If you want some more flexibility you can use:

[NSGIF createGIFfromURL:url withFrameCount:30 delayTime:.010 loopCount:0 completion:^(NSURL *GifURL) {
    NSLog(@"Finished generating GIF: %@", GifURL);
}];

The library is lightweight and very straight forward. Once you grab the URL of your video, pass it to NSGIF alongside the frame count, delay time and loop count. Let me explain those for you:

frameCount - is the amount of frames of the GIF. You can adjust this depending on the resolution of your video. The higher the resolution the lower to frame count!
delayTime  -  is the amount of time for each frame in the GIF.
loopCount  - is the number of times the GIF will repeat. Defaults to 0, which means repeat infinitely.

I recommend you to play with those values and find the best ones for your video.

Demo

Check out the demo project for a quick example of how NSGIF works. After you capture your video, this is what you have to do, to retrieve the GIF:

NSGIF

Todo

  • Add MacOS Demo
  • Auto-calculate the frame count
  • Show preview of GIF in iOS App
  • Create GIFs based on enums for quality type

Pull requests are more than welcomed!

License

Usage is provided under the MIT License. See LICENSE for the full details.

nsgif's People

Contributors

hboon avatar jacobrosenthal avatar khappucino avatar samuelbeek avatar sebyddd avatar smhjsw avatar tonku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nsgif's Issues

Support for large number of frames

Hi All

NSGIF is a great tool to convert videos. But I am having issues converting videos to gifs.
Usually, a gif does not need to be too sensitive on FPS. But when I am creating a gif file with frames more a certain number, eg. 100, the app gets crashed very easily. I found the reason is caused by the CGImageDestinationFinalize. When finalizing the images, I can see that it brings all image frames into memory and crashed the app.

Anyone has ideas to deal with large number of frames in conversion?

Can you add a progress block?

It costs time when copy images from asset to gif, maybe add a progress block will be better. We could see a progress when converting a long video.

Gif Conversion creates memory leak.

This small Objective-C library converts videos to animated Gifs. Unfortunately, the library contains a memory leak which fails to release approximately the same amount of memory as the final size of the gif. Eventually this leads to a crash after multiple sequential conversions.

(This is a duplicate of the previous open issue. I have reposted to make a more concise explanation of the problem for the bugbounty)

How to release memory?

Hi ,it really helps me a lot.But when I convert a lot times,it takes some memory.I can't free these memory.Can you help me?

Black screen issue with AVPlayer when running createGIFfromURL

I have an AVPlayer with a video and when I run the createGIFfromURL block, it I go home while it's working and reopen the app, the AVPlayer turns black. However, after a while, if I come back to the app , the AVPlayer returns to the screen.

Any ideas as to why this is happening and/or how to fix it?

AVFoundationErrorDomain Code=-11832 "Cannot Open"

I'm using GPUImage to process a video and then save it as a Mov file, once the video is processed, it saves correctly to my video library.

UISaveVideoAtPathToSavedPhotosAlbum (pathToMovie, self, @selector(video:didFinishSavingWithError:contextInfo:), NULL);

in the didFinishSavingWithError function take the video URL and try to run it through NSGIF

  • (void)video: (NSString *) videoPath didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo;

    NSURL *fileURL = [NSURL fileURLWithPath:videoPath];
    [NSGIF createGIFfromURL:fileURL withFrameCount:30 delayTime:.010 loopCount:0 completion:^(NSURL *GifURL) {
    NSLog(@"Finished generating GIF: %@", GifURL);
    }];

    if (error) {
    NSLog(@"Error Saving Video To Library: %@", error);
    // Do anything needed to handle the error or display it to the user
    } else {
    NSLog(@"Saved Video To Library:");
    }

}

However I constantly get the following error

Error copying image: Error Domain=AVFoundationErrorDomain Code=-11832 "Cannot Open" UserInfo={NSUnderlyingError=0x12750ed50 {Error Domain=NSOSStatusErrorDomain Code=-12431 "(null)"}, NSLocalizedFailureReason=This media cannot be used., NSLocalizedDescription=Cannot Open}
2016-03-24 16:06:37.191 PhotoBooth[1123:444110] Error copying image and no previous frames to duplicate

Any idea what is causing this?

ImageIO_GIF_Data Memory Leak

I'm seeing about 30mb of memory that is not being released under the category VM: ImageIO_GIF_Data.

Even after deleting the gif the memory remains allocated.

Any advice?

Thank you for your time

screen shot 2016-03-20 at 11 37 11 am

Demo crashes in simulator

Reason : Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'

As its not handled while using image picker in simulator

GIF not recognised in other app.

Once GIF is created and stored in iPhone Photos, Its not getting recognised as GIF for other apps.
e.g in Twitter app, Saved GIF in Photos not getting recognised as gif. Other GIF which are not created using NSGIF and stored in Photos are recognised.

Compression

Hi guys,

Great library! Thanks for building this.

I would like to add additional compression to the gifs. It's my understanding that this can be done by reducing the number of colors or increasing redundant patterns along scan lines.

Gifscicle is a command line utility that can compress gifs. Cloudinary is a cloud platform that can do it, too. So I know it's possible but it doesn't look to be easy in Objective-C and Core Graphics.

Does anyone have any advice? Any freelance developers looking for a quick gig?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.