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

3

8

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?

Acrylonitrile answered 7/3, 2012 at 10:17 Comment(0)
S
16

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

Stonefish answered 7/3, 2012 at 10:49 Comment(1)
Does that mean a GIF effectively has a variable frame rate?Lehr
K
1

The R package av is able to return the frame rate:

> av::av_media_info("tutcup.gif")
$duration
[1] 10.81

$video
  width height codec frames framerate format
1   420    315   gif    173        16   bgra

$audio
NULL
Kerstinkerwin answered 13/3, 2022 at 6:21 Comment(0)
R
0

The GIF format specifies render duration (delay) per each frame, set in milliseconds. Each frame can have a different duration, which makes it impossible to calculate the overall FPS.

Recountal answered 28/6, 2020 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.