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

조회 수: 16 (최근 30일)
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

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 17일
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
  댓글 수: 1
Emerson De Souza
Emerson De Souza 2012년 1월 17일
Hi Chandra,
thank you many times for your attention.
It was a great help, it does exactly what I wanted.
Wish you a nice day
Emerson

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by