Event on GIF reset
6 views (last 30 days)
Show older comments
Kacper Muszynski
on 2 Aug 2022
Commented: Kacper Muszynski
on 3 Aug 2022
Hello all.
Currently devloping an app with appdesiner.
I have an image object, which is playing a GIF.
I would like to collect a timestamp each time the gif resets, or plays a sequence of frames fully.
Alternatively, is there a way of collecting and index for the current frame being displayed?
This is the line that begins displaying the gif:
app.Image.ImageSource = 'C:\Users\user\Desktop\GifFolder\4_7_8.gif';
Thanks,
Kacper.
Accepted Answer
Adam Danz
on 3 Aug 2022
Edited: Adam Danz
on 3 Aug 2022
Without knowing the end goal, I'm not certain this will be useful but it sounds like what you're looking for can be computed or at least approximated by looking at the GIF file properties.
The first section below shows how to compute the duration of a GIF file but rendering delay may add to the actual cycle duration of a GIF file.
The second section below shows how to pull apart a GIF into single frame data but if you're going to match a frame to a template such as frame 1, that will surely add processing delays as well.
Getting frame count and frame delay from a GIF file
The number of frames of a GIF and the DelayTime for each frame can be extracted using imfinfo. Using this example GIF from Wiki (also attached)
file = 'Rotating_earth_(large).gif';
info = imfinfo(file)
info is a structure containing information about each frame of the GIF.
% Count number of frames
nFrames = numel(info)
% Extract delay from each frame (in 1/100 sec)
delay = [info.DelayTime]
% Compute total duration of GIF in seconds
totDur = sum(delay/100)
Analyzing a GIF frame-by-frame
If you want to go deeper and analyze frames, read in the GIF frames using imread
[gifImage, map] = imread(file, 'Frames', 'all');
size(gifImage)
class(gifImage)
Or, if it's easier to work with a movie rather than a GIF, you could convert the GIF to an AVI or another format. See gif2avi from the File Exchange, be sure to use the native GIF frame rate.
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!