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

5 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Chandra Kurniawan
Chandra Kurniawan el 17 de En. de 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
  1 comentario
Emerson De Souza
Emerson De Souza el 17 de En. de 2012
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by