Conversion from 2D images to video

3 views (last 30 days)
Zainb
Zainb on 5 Jun 2015
Commented: Zainb on 24 Jun 2015
Hi all. I want to convert 2D(x,y) images to video. Can anyone please help me out to solve this. I want a solution ASAP. Thank you.

Accepted Answer

Walter Roberson
Walter Roberson on 5 Jun 2015
Use the videowriter class. There are examples http://www.mathworks.com/help/matlab/ref/videowriter-class.html
  3 Comments
Walter Roberson
Walter Roberson on 9 Jun 2015
writerObj = videowriter('OutFile.avi');
writerObj.Framerate = 30;
fileinfo = dir('*.jpg'); %get list of files in current directory
for K = 1 : length(fileinfo)
thisfilename = fileinfo(K).name; %current file name
thisimage = imread(thisfilename); %read image from file
writeVideo(writerObj, thisimage); %a frame is an image
end
close(writerObj);
Note: if you named your files things like frame1.jpg, frame2.jpg, ... frame10.jpg, frame11.jpb, then you will encounter problems with this short code, as it will do them in the order frame1.jpg, frame10.jpg, frame11.jpg, frame2.jpg, .. frame9.jpg as that is the order that the names sort into. There are routines in the File Exchange that can understand "natural" order of files that should have been created with leading 0's in the name, frame0001.jpg, frame0002.jpg, frame0010.jpg and so on.
Zainb
Zainb on 24 Jun 2015
Wow! it worked for me, Thank you a lot :)

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 9 Jun 2015
Attached is a demo. It extracts frames from a video to separate image files, then it reverses the process, going from separate image files to a video, basically using the process Walter showed.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!