PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

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

 May 06, 2022     animated-gif, frame-rate, image, iphone, objective-c     No comments   

Issue

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?


Solution

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



Answered By - AnthonyBlake
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing