Making a video by selecting png images

1 view (last 30 days)
Joydeb Saha
Joydeb Saha on 8 Sep 2021
Answered: Image Analyst on 8 Sep 2021
How can I make a video by selecting png images from a folder? Also how can I save the video?
the files are: abc_20190304_0001.png to abc_20190304_0095.png

Answers (2)

Walter Roberson
Walter Roberson on 8 Sep 2021
Loop over the files by constructing their names. Or read the directory and loop over the files returned by dir().
A common challenge when using information returned by dir() is that numbers are usually sorted in an order people do not expect. abc1.png abc10.png abc11.png abc12.png ... abc19.png abc2.png abc20.png abc21.png and so on. However, I see that in your case the filenames use 4 digit number suffixes with 0 fill, and under that circumstance, you can use the order returned by dir() [though in theory you should sort() the file names, in practice you do not need to if you are using NTFS or any of the common Mac or Linux file systems.]
Use videoWriter() to create a movie object. Read one input file at a time and writeVideo() it to the movie object. https://www.mathworks.com/help/matlab/ref/videowriter.html

Image Analyst
Image Analyst on 8 Sep 2021
I do this in the attached example. I take a video and then write all the frame to disk as individual files. Then I reconstruct a new image by reading in all the frames from the disk and making them into a new movie/video.

Community Treasure Hunt

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

Start Hunting!