Reputation: 47
I want to re-write GIF file with the equal delay time with the original file. This is the example image :
This is my code, but the output has slower delay than the original. Is there a way to make it equals?
[I map]=imread('a.gif');
delay=0.1;
frame=size(I,4);
loops=65535;
for i = 1:frame
if i==1
imwrite(I(:,:,:,i),map,'b.gif','gif','LoopCount',loops, 'DelayTime', delay); %save file output
else
imwrite(I(:,:,:,i),'b.gif','gif','WriteMode', 'append'); %save file output
end
end
Upvotes: 0
Views: 5270
Reputation: 2634
For newer versions of Matlab, imread
also inputs the frame index:
filename = 'a.gif';
output = 'b.gif';
delay= 0.03;
frames = numel(imfinfo(filename));
for i = 1:frames
disp("Working on frame " + i + " out of " + frames)
[I, map] = imread(filename, i);
if i==1
imwrite(I,map, output, 'gif', 'DelayTime', delay,'LoopCount',inf); %save file output
else
imwrite(I, output, 'gif','WriteMode', 'append', 'DelayTime', delay); %save file output
end
end
Upvotes: 0
Reputation: 2132
Use this code
[I map]=imread('a.gif');
delay=0.03;
frame=size(I,4);
for i = 1:frame
if i==1
imwrite(I(:,:,:,i),map,'b.gif','gif', 'DelayTime', delay,'LoopCount',inf); %save file output
else
imwrite(I(:,:,:,i),'b.gif','gif','WriteMode', 'append', 'DelayTime', delay); %save file output
end
end
Upvotes: 1