Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HUGE memory spike causes crash even for 1 frame per second on a 60 second long mp4 video #8

Closed
Pranoy1c opened this issue Aug 4, 2016 · 3 comments

Comments

@Pranoy1c
Copy link

Pranoy1c commented Aug 4, 2016

I have a 3.9 MB 60 second long mp4 video which I am trying to convert to GIF. Testing on iOS 9.3.
Even when I have set the request.framesPerSecond to 1 which should only have 60 total frames in the entire GIF, my app memory spikes to around 270 MB.

Looking further, the memory spike occurs at the if (!CGImageDestinationFinalize(destination)) {
line of the createGIFforTimePoints method. Any clue what can be done to fix this?

NSURL *videoURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"clip" ofType:@"mp4"]];
    NSString *destinationPath = [[self applicationDocumentsDirectory].path
                                 stringByAppendingPathComponent:@"mygif.txt"];

    NSGIFRequest * request = [NSGIFRequest requestWithSourceVideo:videoURL destination:[NSURL fileURLWithPath:destinationPath]];
    request.framesPerSecond=1;
    request.scalePreset=NSGIFScaleOptimize;
    request.progressHandler = ^(double progress, NSUInteger position, NSUInteger length, CMTime time, BOOL *stop, NSDictionary *frameProperties) {
        NSLog(@"%f - %lu - %lu - %lld - %@", progress, (unsigned long)position, (unsigned long)length, time.value, frameProperties);
    };

    [NSGIF create:request completion:^(NSURL *GifURL) {
        //GifURL is to nil if it failed or stopped.
    }];
@Pranoy1c
Copy link
Author

Pranoy1c commented Aug 4, 2016

setting the scalePreset to NSGIFScaleVeryLow and request.framesPerSecond=5 reduces the memory to 100MB which is sort of acceptable. though pretty bad quality. My original video is 640x360 resolution. So the line NSGIFScaleRatio when set to NSGIFScaleOptimize was falling in the NSGIFScaleMedium case of the switch statement which meant it would scale to .5. This is most likely the cause of the issue.

@metasmile
Copy link
Owner

Sorry too late. But I'm working to fix that issue!
I'll notify when release the new version.

@metasmile
Copy link
Owner

New version 1.5 was released. please type. Maybe you can perfectly resolve at this version.

pod update NSGIF2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants