How to save image of a video.avi file into the folder where Matlab is running as image.bmp file?

14 views (last 30 days)
Motivation: I'm currently using VirtualDub v1.9.11 (Free Software) to load a video.avi file and extract all images one by one and save them as .bmp, which later I use in Matlab.
What I want to do: I would like to load a video.avi file and save each image of the video in the current folder where Matlab is running using the following naming and extension: 1.bmp 2.bmp 3.bmp n.bmp and so son.
*What I have done so far:* Until now I know only to load the video using the command lines below:
cd 'C:\Program Files\MATLAB\R2011a\toolbox\vision\visiondemos';
M = mmreader('shaky_car.avi');
N = M.NumberOfFrames;
for ii = 1:N
image(M.read(ii));
pause(0.1);
end
cd C:\Users\Emerson\Desktop\MOVIE_ANALYSIS
For this particular case, the video shaky_car.avi has 132 images, so the folder would be filled with the files 1.bmp, 2.bmp, 3.bmp, and so on until 132.bmp.
I wonder if someone could tell me how to write the command lines to do this job.
Thanks in advance for your help
Emerson

Accepted Answer

Chandra Kurniawan
Chandra Kurniawan on 17 Jan 2012
Hi,
'shaky_car.avi' is already exist in visiondemos folder,
so you do not need to change the directory by
cd 'C:\Program Files\MATLAB\R2011a\toolbox\vision\visiondemos';
Just try my code and I hope this works on your machine.
obj = mmreader('shaky_car.avi');
vid = read(obj);
nFrame = size(vid,4);
for k = 1 : nFrame
newname = strcat(num2str(k),'.bmp');
imwrite(vid(:,:,:,k), newname);
end

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!