Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Movies and Pictures

Subject: Movies and Pictures

From: Idan

Date: 1 May, 2009 20:02:02

Message: 1 of 5

Hello all,

I have a question, I've looked everywhere, and found only partial information regarding what I'm looking for.
Say I have an .avi movie called: "movie.avi".
The questions are as followed:
1) How do I know how many frames are in the movie?
2) I'm using the command: mov=aviread('movie.avi');
    in order to read the movie file into Matlab's memory.
    Now, all I want to do is to create a set of pictures (It doesn't matter which
    extension does the picture have - bmp, jpeg, etc...).
    Suppose the movie consists of 10 frames, I would like to export 10 images.

Any help would be appreciated - It's for my final project in my B.S.c degree :)
Thanks in advance,

Idan.
idanisra@hotmail.com

Subject: Movies and Pictures

From: Pieter van Geer

Date: 8 May, 2009 13:12:01

Message: 2 of 5

Hi Idan,

> 1) How do I know how many frames are in the movie?
aviinfo provides information regarding your avi file. This includes the number of frames

> 2) I'm using the command: mov=aviread('movie.avi');
> in order to read the movie file into Matlab's memory.
> Now, all I want to do is to create a set of pictures (It doesn't matter which
> extension does the picture have - bmp, jpeg, etc...).
> Suppose the movie consists of 10 frames, I would like to export 10 images.

The output of aviread consists of cdata and a colormap. These exact two variables can be used to plot the frame in a matlab figure. For example:

%% Load a frame
[cdata map]=aviread('movie.avi',1); % read the first frame

%% create the figure
figure('color','w')
image(cdata)
colormap(map)
axis off % Remove axis ticks and numbers
axis image % Set aspect ratio to obtain square pixels

%% store the figure
saveas(gcf,'givename.ext');
close(gcf);

Hope this example works for you.

Good luck with it!

Pieter

Subject: Movies and Pictures

From: Syed Ali

Date: 29 Oct, 2009 02:30:20

Message: 3 of 5

Dear Sir,

I have try to exectue your code and find out the following error:

Error in ==> testing2 at 2
[cdata map]=aviread('abc.avi',1); % read the first frame
Too many output arguments.

could u please help me,
I want to read the avi file, take out the frames
and read each pixel of each frame and change the
values and then store it.

Regards
Syed

Subject: Movies and Pictures

From: Pieter van Geer

Date: 8 Mar, 2010 12:47:05

Message: 4 of 5

Dear Syed,

You are right. There is a small error in that code. aviread only gives one output variable. This variable contains the cdata and colormap. Find the updated code below.

%% Load a frame
mov = aviread('movie.avi',1); % read the first frame
map = mov.colormap;
cdata = mov.cdata;

%% create the figure
figure('color','w')
image(cdata)
colormap(map)
axis off % Remove axis ticks and numbers
axis image % Set aspect ratio to obtain square pixels

%% store the figure
saveas(gcf,'givename.ext');
close(gcf);

Pieter

Subject: Movies and Pictures

From: Pieter van Geer

Date: 8 Mar, 2010 12:48:20

Message: 5 of 5

Dear Syed,

You are right. There is a small error in that code. aviread only gives one output variable. This variable contains the cdata and colormap. Find the updated code below.

%% Load a frame
mov = aviread('movie.avi',1); % read the first frame
map = mov.colormap;
cdata = mov.cdata;

%% create the figure
figure('color','w')
image(cdata)
colormap(map)
axis off % Remove axis ticks and numbers
axis image % Set aspect ratio to obtain square pixels

%% store the figure
saveas(gcf,'givename.ext');
close(gcf);

Pieter

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us