Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

mmreader - Create multimedia reader object for reading video files

Syntax

obj = mmreader(filename)
obj = mmreader(filename, 'P1', V1, 'P2', V2,...)

Description

obj = mmreader(filename) constructs a multimedia reader object, obj, that can read video data from a multimedia file named filename. The mmreader function searches for the file on the MATLAB path, and generates an error if it cannot construct the object for any reason.

mmreader supports the following file formats:

PlatformSupported File Formats

Windows, Macintosh, and Linux

Motion JPEG 2000 (.mj2)

Windows

AVI (.avi),
MPEG-1 (.mpg),
Windows Media Video (.wmv, .asf, .asx),
and any format supported by Microsoft DirectShow.

Macintosh

AVI (.avi),
MPEG-1 (.mpg),
MPEG-4 (.mp4, .m4v),
Apple QuickTime Movie (.mov),
and any format supported by QuickTime as listed on http://www.apple.com/quicktime/player/specs.html.

Linux

Any format supported by your installed plug-ins for GStreamer 0.10 or above, as listed on http://gstreamer.freedesktop.org/documentation/plugins.html, including AVI (.avi) and Ogg Theora (.ogg).

There are no restrictions on file extensions. For more information, see Supported Video File Formats in the MATLAB Data Import and Export documentation

obj = mmreader(filename, 'P1', V1, 'P2', V2,...) constructs a multimedia object and assigns values V1, V2, etc. to the respective specified properties P1, P2, etc. If you specify an invalid property name or property value, MATLAB throws an error and does not create the object. Property value pairs can be in any format supported by the set function: parameter-value string pairs, structures, or parameter-value cell array pairs. The mmreader object supports the following properties:

PropertyDescriptionRead-OnlyDefault Value
BitsPerPixelBits per pixel of the video dataYes 
DurationTotal length of file in seconds Yes 
FrameRateFrame rate of the video in frames per secondYes 
HeightHeight of the video frame in pixelsYes 
NameName of the file from which the reader object was createdYes 
NumberOfFramesTotal number of frames in the video streamYes 
PathString containing the full path to the file associated with the readerYes 
TagGeneric string for you to setNo''
TypeClass name of the objectYesmmreader
UserDataGeneric field for any user-defined dataNo[]
VideoFormatString indicating the video format as it is represented in MATLAB, e.g., RGB24Yes 
WidthWidth of the video frame in pixelsYes 

Remarks

Some files store video at a variable frame rate, including many Windows Media Video files. For these files, mmreader cannot determine the number of frames until you read the last frame. When you construct the object, mmreader returns a warning and does not set the NumberOfFrames property.

To count the number of frames in a variable frame rate file, call the read function to read the last frame of the file. For example:

vidObj = mmreader('varFrameRateFile.wmv');
lastFrame = read(vidObj, inf);
numFrames = vidObj.NumberOfFrames;

Because mmreader must decode all video data to count the frames reliably, the call to read sometimes takes a long time to run. For more information, see Reading Variable Frame Rate Video in the MATLAB Data Import and Export documentation.

Examples

Read and play back the movie file xylophone.mpg.

xyloObj = mmreader('xylophone.mpg');

nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;

% Preallocate movie structure.
mov(1:nFrames) = ...
    struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
           'colormap', []);

% Read one frame at a time.
for k = 1 : nFrames
    mov(k).cdata = read(xyloObj, k);
end

% Size a figure based on the video's width and height.
hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight])

% Play back the movie once at the video's frame rate.
movie(hf, mov, 1, xyloObj.FrameRate);

See Also

get (hgsetget), mmfileinfo, read (mmreader), set (hgsetget)

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS