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

14 ビュー (過去 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 Center および File ExchangeImport, Export, and Conversion についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by