MATLAB: Joining jpg files to make a video

Image Processing Toolboxvideo processing

I have a certain number of sequential images in a folder named "Snaps". I want a source code in matlab so that i can join them together to make a video. Please help. p.s. I am using matlab 2010a

Best Answer

I use MATLAB2012a, you can try if this function works for you. The input arguments are: the path to the images (vide_dir), extention of the images (extension), path and name of the video with extension (aviname), and the frame rate (fps)
For example: make_video('/home/user/myImages/','jpg','myvideo.avi',5)
function make_video(video_dirs,extension,aviname,fps)
resnames=dir(fullfile(video_dirs,['*.' extension]));
aviobj=VideoWriter(aviname);
aviobj.FrameRate=fps;
open(aviobj);
for i=1:length(resnames)
img=imread(fullfile(video_dirs,resnames(i).name));
F=im2frame(img);
if sum(F.cdata(:))==0
error('black');
end
writeVideo(aviobj,F);
end
close(aviobj);
end