Вот что я использую для разделения видео и объединения их в анимированные GIF. Я уверен, что вы можете приспособить его к тому, что вам нравится. Он полностью основан на фрагментах кода из справки MATLAB.
function [ startframe, endframe ] = catgif( inputvideoname, outputfilename,...
startframe, endframe, preview)
InputVideo = VideoReader(inputvideoname);
filename = outputfilename;
if (endframe > InputVideo.NumberOfFrames)
endframe = InputVideo.NumberOfFrames;
end
figure(1)
for ii = 1:endframe
if (ii >= startframe)
img = read(InputVideo,ii);
%Resize or rotate as appropriate.
%img = imresize(imrotate(img, -90),0.5, 'bicubic');
img = imresize(img,0.5, 'bicubic');
imshow(img,'Border','tight');
drawnow
frame = getframe(1);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if ~strcmp(preview, 'yes')
if ii == startframe;
imwrite(imind,cm,filename,'gif', 'DelayTime', 0, 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','DelayTime', 0, 'WriteMode','append');
end
end
end
end