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:
How to obtain image frames from AVI file?

Subject: How to obtain image frames from AVI file?

From: Ross

Date: 7 Nov, 2007 02:25:40

Message: 1 of 10

I'm trying to extract a certain set of image frames from a
movie file.

So far, I know how to use aviread to read the avi file into
matlab memory. I also know how to use frame2im to obtain a
single desired frame from the matlab file and then convert
it into a grayscale image.

However, I don't how to obtain a range of frames.

After I run

a=aviread('movie.avi')

Is there any function/code that will let me extract either
all the image frames from the movie or a section of the
image frames?

Also, I need the image frames to be grayscale.

Thanks

Subject: How to obtain image frames from AVI file?

From: Andrew

Date: 7 Nov, 2007 04:05:21

Message: 2 of 10

You may have a problem since

a=aviread('movie.avi');

Should extract all of the frames. If you look at the help
you can also add indexs for the frames you want, like

a = aviread('movie.avi', 1:5);

If the image colours aren't indexed you can convert them to
greyscale with rgb2gray (a.colormap will be empty)

Gray = rgb2gray(a(1).cdata);
figure; imagesc(Gray);
colormap(gray);

I haven't played with colour indexed images in Matlab
before though.

Cheers,
Andrew

"Ross " <ross.nospam.kozz@yahoo.com> wrote in message
<fgr7n4$pga$1@fred.mathworks.com>...
> I'm trying to extract a certain set of image frames from
a
> movie file.
>
> So far, I know how to use aviread to read the avi file
into
> matlab memory. I also know how to use frame2im to obtain
a
> single desired frame from the matlab file and then
convert
> it into a grayscale image.
>
> However, I don't how to obtain a range of frames.
>
> After I run
>
> a=aviread('movie.avi')
>
> Is there any function/code that will let me extract
either
> all the image frames from the movie or a section of the
> image frames?
>
> Also, I need the image frames to be grayscale.
>
> Thanks

Subject: How to obtain image frames from AVI file?

From: Nick Haddad

Date: 7 Nov, 2007 17:42:48

Message: 3 of 10

Ross,

If you are using MATLAB R2007a and later you can use the new mmreader
function to extract your frames and then convert the data to grayscale
using rgb2gray. For example

% create an mmreader object
videoObject = mmreader('movie.avi');


% extract frames 1 through 5
imageData = read( videoObject, [1 5] );

% convert the data to grayscale
grayData = rgb2gray( imageData );

MMReader will also work on other video types, including mpeg-1 and
Windows Media video files.

-Nick

Ross wrote:
> I'm trying to extract a certain set of image frames from a
> movie file.
>
> So far, I know how to use aviread to read the avi file into
> matlab memory. I also know how to use frame2im to obtain a
> single desired frame from the matlab file and then convert
> it into a grayscale image.
>
> However, I don't how to obtain a range of frames.
>
> After I run
>
> a=aviread('movie.avi')
>
> Is there any function/code that will let me extract either
> all the image frames from the movie or a section of the
> image frames?
>
> Also, I need the image frames to be grayscale.
>
> Thanks

Subject: How to obtain image frames from AVI file?

From: Dave Tarkowski

Date: 7 Nov, 2007 19:16:50

Message: 4 of 10

Ross wrote:
> I'm trying to extract a certain set of image frames from a
> movie file.
>
> So far, I know how to use aviread to read the avi file into
> matlab memory. I also know how to use frame2im to obtain a
> single desired frame from the matlab file and then convert
> it into a grayscale image.
>
> However, I don't how to obtain a range of frames.
>
> After I run
>
> a=aviread('movie.avi')
>
> Is there any function/code that will let me extract either
> all the image frames from the movie or a section of the
> image frames?
>
> Also, I need the image frames to be grayscale.
>
> Thanks

You can read a range of frames using aviread. To read frames 10 through
93 you would use:

a = aviread('movie.avi', 10:93);

You can then convert the data into image data and convert those images
into grayscale images.

If you are using R2007b on Windows, you can also use the new MMREADER
functionality:

mov = mmreader('movie.avi');
data = read(mov, [10 93]);

would do the same as the AVIREAD command above except that you do not
need to use frame2im with the output of MMREADER. Also, MMREADER is
more robust and can read a larger variety of file types than AVIREAD.

-Dave Tarkowski

Subject: How to obtain image frames from AVI file?

From: Ross

Date: 9 Nov, 2007 02:29:30

Message: 5 of 10

Thank you all so much! That helps a lot.

I can now successfully extract and process frames for my
application.

Thanks again!

Subject: How to obtain image frames from AVI file?

From: sweety

Date: 28 Aug, 2012 15:09:52

Message: 6 of 10

On Wednesday, November 7, 2007 7:55:40 AM UTC+5:30, Ross wrote:
> I'm trying to extract a certain set of image frames from a
> movie file.
>
> So far, I know how to use aviread to read the avi file into
> matlab memory. I also know how to use frame2im to obtain a
> single desired frame from the matlab file and then convert
> it into a grayscale image.
>
> However, I don't how to obtain a range of frames.
>
> After I run
>
> a=aviread('movie.avi')
>
> Is there any function/code that will let me extract either
> all the image frames from the movie or a section of the
> image frames?
>
> Also, I need the image frames to be grayscale.
>
> Thanks









fin = 'e:\in.avi';
fout = 'd:\out.avi';
fileinfo = aviinfo(fin);
nframes = fileinfo.NumFrames;
aviobj = avifile(fout, 'compression', 'none', 'fps',
fileinfo.FramesPerSecond);
for i = 1:nframes
    %Read frames from input video
    mov_in = aviread(fin,i);
    im_in = frame2im(mov_in);
    gr=rgbgray(im_in);

Subject: How to obtain image frames from AVI file?

From: gittogeorgethampi@gmail.com

Date: 25 Sep, 2012 10:42:18

Message: 7 of 10

On Wednesday, November 7, 2007 11:12:48 PM UTC+5:30, Nick Haddad wrote:
> Ross,
>
> If you are using MATLAB R2007a and later you can use the new mmreader
> function to extract your frames and then convert the data to grayscale
> using rgb2gray. For example
>
> % create an mmreader object
> videoObject = mmreader('movie.avi');
>
>
> % extract frames 1 through 5
> imageData = read( videoObject, [1 5] );
>
> % convert the data to grayscale
> grayData = rgb2gray( imageData );
>
> MMReader will also work on other video types, including mpeg-1 and
> Windows Media video files.
>
> -Nick
>
> Ross wrote:
> > I'm trying to extract a certain set of image frames from a
> > movie file.
> >
> > So far, I know how to use aviread to read the avi file into
> > matlab memory. I also know how to use frame2im to obtain a
> > single desired frame from the matlab file and then convert
> > it into a grayscale image.
> >
> > However, I don't how to obtain a range of frames.
> >
> > After I run
> >
> > a=aviread('movie.avi')
> >
> > Is there any function/code that will let me extract either
> > all the image frames from the movie or a section of the
> > image frames?
> >
> > Also, I need the image frames to be grayscale.
> >
> > Thanks


can u please help me to extract all the frames in a video and display it as images? i tried many codes. but my program is not showing anything.it is nt even showing an error.

Subject: How to obtain image frames from AVI file?

From: vuhoangnguyen49@gmail.com

Date: 1 Oct, 2012 13:36:59

Message: 8 of 10

I am doing my senior project about image processing. you said that you can extract and process frames for your appication. Could you instruct me the step to extract and covert frame to grayscale imgage. thanks alot

Subject: How to obtain image frames from AVI file?

From: thematlabguy@gmail.com

Date: 26 Jan, 2013 09:09:42

Message: 9 of 10

for extracting frames from a video and saving it into a specific folder,code is given,visit

http://matlabnstuff.blogspot.in/2013/01/extracting-frames-from-video-file.html

modify a little bit,your task will be done :)

Subject: How to obtain image frames from AVI file?

From: b.shahab2@gmail.com

Date: 9 Mar, 2014 15:07:33

Message: 10 of 10

Hi sweety:
ur code is perfect but wehn i try to convert the frames2im it tells me you have to use getframe function inorder to get the frames , any idea how to convert those frames into pictures without fram2im and i dont want the imwrite

Tags for this Thread

No tags are associated with 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