Create a movie from images
48 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have saved some images to a directory and would now like to play these as a movie.
This is what i have done:
% load the images
images = cell(30,1);
for i=1:30
images{i} = imread(sprintf('%d.jpg',i));
end
% create the video writer with 30 fps
writerObj = VideoWriter('Velocity.avi');
writerObj.FrameRate = 30;
% open the video writer
open(writerObj);
% write the frames to the video
for u=1:30
% convert the image to a frame
frame = im2frame(images{u});
for v=1:30
writeVideo(writerObj, frame);
end
end
% close the writer object
close(writerObj);
implay('Velocity.avi');
This creates a video, but the frame rate is not what i expected; it creates a video of 900 frames and jumps 30 frames a second.
I guess writerObj.FrameRate = 30 doesn't do what i originally thought. Nut now i'm unsure how to get it to play at a rate of 30 frames per second.
Also, why does the video have 900 frames when i only have 30 images?
Help much appreciated.
0 commentaires
Réponse acceptée
N B
le 4 Mar 2016
Modifié(e) : N B
le 4 Mar 2016
1 commentaire
Josep Llobet
le 4 Août 2021
Modifié(e) : Josep Llobet
le 4 Août 2021
True!
I did the same.
Thank you for the code
Plus de réponses (1)
Guillaume
le 4 Mar 2016
I don't think that the call to im2frame is necessary. You can directly write the image returned by imread to the video. (I've never used im2frame, I'm not sure what effect it has in your case).
For each image, you have a v loop that writes it 30 times. 30 images written 30 times = 900 frames. The frame rate does what you asked it. It plays the video at 30 frames per second, but since each group of 30 frame is identical you have in effect 1 different image per second.
Why are writing the same image 30 times?
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!