Search code examples
matlabgif

Writing delay time of GIF file in matlab


I want to re-write GIF file with the equal delay time with the original file. This is the example image :

input

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 

The result: enter image description here


Solution

  • 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