Event on GIF reset

2 ビュー (過去 30 日間)
Kacper Muszynski
Kacper Muszynski 2022 年 8 月 2 日
コメント済み: Kacper Muszynski 2022 年 8 月 3 日
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.
  1 件のコメント
Adam Danz
Adam Danz 2022 年 8 月 3 日
I'm curious what the end goal is here.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2022 年 8 月 3 日
編集済み: Adam Danz 2022 年 8 月 3 日
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 = 1×44 struct array with fields:
Filename FileModDate FileSize Format FormatVersion Left Top Width Height BitDepth ColorType FormatSignature BackgroundColor AspectRatio ColorTable Interlaced DelayTime DisposalMethod TransparentColor
info is a structure containing information about each frame of the GIF.
% Count number of frames
nFrames = numel(info)
nFrames = 44
% Extract delay from each frame (in 1/100 sec)
delay = [info.DelayTime]
delay = 1×44
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
% Compute total duration of GIF in seconds
totDur = sum(delay/100)
totDur = 3.9600
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)
ans = 1×4
400 400 1 44
class(gifImage)
ans = 'uint8'
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.
  1 件のコメント
Kacper Muszynski
Kacper Muszynski 2022 年 8 月 3 日
Thank you very much. This is more than enough.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by