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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With