6

I have 10 images in the folder say "D:\images\" named as frame1,frame2,...,frame10. I want to make a movie from the color images with frame rate as per choice.Also i want to save created video file in .mp4 format at the location "D:\video\".

Is it possible to do so in MATLAB?how?

Royi
  • 33,983
  • 4
  • 72
  • 179
ramdas1989
  • 332
  • 2
  • 11

1 Answers1

5

It is easy to do using the VideoWriter class.

You easily add frame (Image) using the proper method which is writeVideo.

After creating a video object, videoObject and given an image by mImage001, adding frame is done by:

writeVideo(videoObject, mImage001);

Enjoy...

Code Sample

Here is a code sample based on Mathworks documentation with some remarks of mine:

% Creating Video Writer Object
writerObj = VideoWriter('peaks.avi');
% Using the 'Open` method to open the file
open(writerObj);

% Creating a figure.
% Each frame will be a figure data
Z = peaks; surf(Z); 
axis tight
set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer');

for k = 1:20 
   surf(sin(2*pi*k/20)*Z,Z)
   % Frame includes image data
   frame = getframe;
   % Adding the frame to the video object using the 'writeVideo' method
   writeVideo(writerObj,frame);
end

% Closing the file and the object using the 'Close' method
close(writerObj);

This should be straight forward.

Royi
  • 33,983
  • 4
  • 72
  • 179