GIF speed not as expected! Help!
77 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello. I am trying to generate a GIF of a growing bar. However, the speed of the generating gif is really slow, and I don't understand how to make it faster. The 'DelayTime' is set to 0, and when the animation is generated in MATLAB is looks really fine. However, when I open the bar.gif, the animation is not fluid at all. This is the code
%draw rectangle and lambda
clear;
figure();
rectangle('Position',[0 2 10 1]);
axis off
set(gcf,'Position',[ -901 789 579 70])
t=0:0.05:3
l=1; a=0.5
p=@(t,l,a) 1-(1-a).*exp(-l.*t);
x=[0 0 10 10];
y=[2 3 3 2];
patch(x,y,'white');
frame=getframe(gca); im=frame2im(frame);
[imind,cm] = rgb2ind(im,256);
filename='bar.gif';
imwrite(imind,cm,filename,'gif','DelayTime',0.5, 'Loopcount',inf);
for tt=1:length(t)
pt=p(t(tt),l,a);
x=[0 0 10.*pt 10.*pt];
patch(x,y,'green');
% pause(.01); drawnow;
frame(tt)=getframe(gca);
end
for tt=1:length(t)
im=frame2im(frame(tt));
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename, 'gif','DelayTime',0,'WriteMode','append');
end
1 Commento
John D'Errico
il 14 Nov 2017
Modificato: John D'Errico
il 14 Nov 2017
@DA Huang: Please don't answer a question with your own question. Use comments to make a comment.
Moved an answer by Da Huang into a comment:
"Have you solve this problem?"
Risposta accettata
Utpal Kumar
il 7 Lug 2017
Edited and the delay time has been set to 0.1 seconds:
%draw rectangle and lambda
clear;
figure();
rectangle('Position',[0 2 10 1]);
axis off
set(gcf,'Position',[ -901 789 579 70])
t=0:0.05:3
l=1; a=0.5
p=@(t,l,a) 1-(1-a).*exp(-l.*t);
x=[0 0 10 10];
y=[2 3 3 2];
patch(x,y,'white');
frame=getframe(gca); im=frame2im(frame);
[imind,cm] = rgb2ind(im,256);
filename='bar.gif';
imwrite(imind,cm,filename,'gif','DelayTime',0.1, 'Loopcount',inf);
for tt=1:length(t)
pt=p(t(tt),l,a);
x=[0 0 10.*pt 10.*pt];
patch(x,y,'green');
% pause(.01); drawnow;
frame(tt)=getframe(gca);
end
for tt=1:length(t)
im=frame2im(frame(tt));
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename, 'gif','DelayTime',0.1,'WriteMode','append');
end
3 Commenti
DGM
il 23 Apr 2023
Short delay times depend entirely on the application to render them at the specified rate. It should be no surprise that at some point, the specified delay time fails to be met. While an exact zero delay time might seem a bit of a stretch, in practice it's worse than that. While most web browsers support delay times below 0.1s, most will treat 0 delay time as 0.1s. In other words, if you try to go too fast, you'll actually get slower results.
A number of people have surveyed this experimentally over the years. Here are two old ones that I found.
From the conclusion on the first link:
The first finding to note is that no modern browser surveyed supports frame delays below 0.02 seconds. Therefore, when creating an animated GIF, one should never use a frame delay below this threshold as it will be entirely ineffectual.
To achieve a high animation rate, set DelayTime to 0.02. Setting DelayTime to a lower value will slow down the actual animation rate in many image viewers and web browsers.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Animation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!