Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the number of frames per second from a gif file?

I am trying to get the number of frames per second from a gif file. I am converting the gif file to NSData and then from that NSData I take an array of frames using this code:

-(NSMutableArray *)getGifFrames:(NSData *)data{
    NSMutableArray *frames = nil;
    CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)data, NULL);
    if (src) {
        size_t l = CGImageSourceGetCount(src);
        frames = [NSMutableArray arrayWithCapacity:l];
        for (size_t i = 0; i < l; i++) {
            CGImageRef img = CGImageSourceCreateImageAtIndex(src, i, NULL);
            if (img) {
                [frames addObject:[UIImage imageWithCGImage:img]];
                CGImageRelease(img);
            }   
        }   
        CFRelease(src);
    } 
    return frames;
}

Is there anyway I can get the FPS of the gif?

like image 846
Legnus Avatar asked Mar 07 '12 10:03

Legnus


People also ask

How do I know how many fps my GIF has?

A GIF file doesn't contain an FPS value, rather each frame contains a duration. Each frame contains a header. Hex Byte Number 324 contains the frame duration in 100ths of a second, for example 09 00 would be 0.09 seconds.

How can you tell the duration of a GIF?

You can compare the durations of the input and output GIFs in your browser by turning the animations on or off with the "Play/Pause GIFs" checkbox.

Can a GIF be 30 fps?

Adjusting the Timeline Frame Rate will change how many frames per second (fps) your animated GIF file will go by. When making an animated GIF in Photoshop, Photoshop is set to 30 fps by default. 30 fps may be good to work, but when creating an animated gif in photoshop you may need to adjust.


1 Answers

A GIF file doesn't contain an FPS value, rather each frame contains a duration.

Each frame contains a header.

Hex Byte Number 324 contains the frame duration in 100ths of a second, for example 09 00 would be 0.09 seconds.

EDIT: reference http://en.wikipedia.org/wiki/Graphics_Interchange_Format#Animated_GIF

like image 109
AnthonyBlake Avatar answered Oct 04 '22 14:10

AnthonyBlake