Make video from images

672 views (last 30 days)
Paul Eluard
Paul Eluard on 23 Apr 2016
Commented: Image Analyst on 28 Oct 2022
Hello !
I have about 500 pics and i'd like to make a video with. Also, i have a vector with the time each image should appear. (Img10 at tome(10))
Is it possible ?
Thank you so much, Loic.
  1 Comment
Matthew Eicholtz
Matthew Eicholtz on 27 Apr 2016
Yes, this should be possible. Is the frame rate constant?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 27 Apr 2016
Edited: Image Analyst on 27 Apr 2016
I was doing almost the same thing today. I'm still in the act of polishing it up, but here is a first draft that works, attached. You specify a folder of images and it builds all the images into an avi movie. You can specify the frame rate, and how many times the first slide shows up (because it might be a title slide).
You could use text() to imprint any text on the frames, such as the time or whatever.
I'm using it to make a time lapse movie of a building they're building here. It will take 3 years to finish the building. I take a picture every day that I'm there. Eventually I also want to figure out how to place each frame at the proper time, but right now it just strings them all together. Feel free to modify it though to do what you want, which will require you writing additional copies of frames in there to make sure the frame you want appears at the proper time.
  12 Comments
atharva aalok
atharva aalok on 15 Sep 2022
Edited: atharva aalok on 15 Sep 2022
@Image Analyst I am using your code for making a movie.
I have a folder with 40 png images. I want to use these to make my movie.
When I run the makeMovie.fig
After selecting the folder I get the following error messages in succession:
What could be wrong here?
(I have aleady added the following lines to the .m file at line 425 as suggested in a previous comment:
try
returnValue = uigetdir(handles.imageFolder,'Select folder');
catch
returnValue = uigetdir(pwd,'Select folder');
end
)
Images in my folder are named as follows:

Sign in to comment.

More Answers (3)

Matthew Eicholtz
Matthew Eicholtz on 27 Apr 2016
I usually use the VideoWriter class for making movies in MATLAB.
Here is some basic code structure to get you started:
video = VideoWriter('yourvideo.avi'); %create the video object
open(video); %open the file for writing
for ii=1:N %where N is the number of images
I = imread('the ith image.jpg'); %read the next image
writeVideo(video,I); %write the image to file
end
close(video); %close the file
Now, this assumes constant frame rate (which can be set using the video.FrameRate property). I am not aware of any built-in functionality for handling variable frame rate. But, in theory, you could hack it by repeating image frames.
For example, if your frame rate is 1 frame per second, and the time vector is something like:
t = [0 2 3 7 ...]; %times for the 1st image, 2nd image, and so forth
Then, you will want to call 'writeVideo(video,I)' 2 times for image 1, 1 time for image 2, 4 times for image 3, etc. This will be challenging if your times are not multiples of your frame rate, so watch out for that.
  6 Comments
Image Analyst
Image Analyst on 4 Mar 2021
Try my code instead. If that still doesn't work, then start a new question and attach 5 of your images.

Sign in to comment.


Pascal Stirtzel
Pascal Stirtzel on 30 Jan 2020
Perfect, thank you very much

Vikas Arora
Vikas Arora on 11 Sep 2022
Edited: Image Analyst on 11 Sep 2022
A small modification to @Matthew Eicholtz's answer:
% If your image file starts with image_1.png, image_2.png and so on ...
% and live in the current folder.
folder = pwd; % Or wherever you want.
video = VideoWriter('yourvideo.avi'); % Create the video object.
open(video); % Open the file for writing
N=601; % Where N is the separate number of PNG image files.
for k = 1 : N
I = imread(fullfile(folder, sprintf('image_%g.png', k))); % Read the next image from disk.
writeVideo(video,I); % Write the image to file.
end
close(video);
  3 Comments
Image Analyst
Image Analyst on 28 Oct 2022
@atharva aalok try a different file extension, like .mp4 or .mpg or .wmv.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by