How do I read in an AVI frame and save it to an image file in MATLAB?
76 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Commented: Eric
on 21 Apr 2017
I would like to process each frame of an AVI file separately. I would like to know how to access the individual frames, what image type I can save these frames in, and if I will have to save the AVI file as something different before I open it in MATLAB.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
Accessing the individual AVI frames is not difficult and can be done in just a few short commands. As far as file types for the images, you can save in whatever file format that imwrite supports in your version of MATLAB.
Take for example an AVI-file called "clock.avi":
% READ THE AVI
mov=aviread('clock.avi');
% GRAB A SINGLE FRAME
[im1,map] = frame2im(mov(1));
% SHOW THE FRAME
imshow( im1 );
% SET THE COLORMAP PROPERLY SO THE IMAGE SHOWS CORRECTLY
colormap( map );
% WRITE OUT THE FRAME TO A BMP FILE
imwrite(im1,map,'clockFrame1.bmp');
For more details, see the documentation of the AVIREAD, FRAME2IM, IMSHOW, and IMWRITE functions used above.
1 Comment
Eric
on 21 Apr 2017
As of R2014b, "aviread" should be changed to "VideoReader". Also, I believe the VideoReader object cannot be indexed to obtain a frame, but rather readFrame(vidObj) must be called. See MATLAB's examples on reading video files.
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!