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

I try to get the number of frames per second from a gif file, I convert the gif file to NSData, and then from this 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; 

}

Anyway, can I get FPS from gif? Thanks you

+6
source share
2 answers

The GIF file does not contain an FPS value, and each frame contains a duration.

Each frame contains a caption.

Hex Byte Number 324 contains a frame duration of 100 seconds, for example, 09 00 will be 0.09 seconds.

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

+10
source

Take a look at this code I found - the AnimatedGif class contains the "GIFReadExtensions" method, which seems to do exactly what you want:

Animated and transparent GIF files for iPhone simplified!

+1
source

Source: https://habr.com/ru/post/910150/


All Articles