MATLAB: How to make an animated GIF file from an AVI file

MATLAB

I would like to use MMREADER and IMWRITE to create an animated GIF file from an AVI file.

Best Answer

In order to convert code from an AVI file to an animated GIF file, follow the steps below. The AVI file is the input and named 'mode15_600p78Hz.avi' and the output file is the GIF file 'test1.gif.'
vrinfo = aviinfo('mode15_600p78Hz.avi');
filename = 'test1.gif';
mov1 = mmreader('mode15_600p78Hz.avi');
vidFrames = read(mov1);
for n = 1:vrinfo.NumFrames
[imind,cm] = rgb2ind(vidFrames(:,:,:,n),255);
if n == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
Related Question