| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
obj = mmreader(filename)
obj = mmreader(filename, 'P1', V1, 'P2', V2,...)
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:
| Platform | Supported File Formats |
|---|---|
Windows, Macintosh, and Linux | Motion JPEG 2000 (.mj2) |
Windows | AVI (.avi), |
Macintosh | AVI (.avi), |
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:
| Property | Description | Read-Only | Default Value |
|---|---|---|---|
| BitsPerPixel | Bits per pixel of the video data | Yes | |
| Duration | Total length of file in seconds | Yes | |
| FrameRate | Frame rate of the video in frames per second | Yes | |
| Height | Height of the video frame in pixels | Yes | |
| Name | Name of the file from which the reader object was created | Yes | |
| NumberOfFrames | Total number of frames in the video stream | Yes | |
| Path | String containing the full path to the file associated with the reader | Yes | |
| Tag | Generic string for you to set | No | '' |
| Type | Class name of the object | Yes | mmreader |
| UserData | Generic field for any user-defined data | No | [] |
| VideoFormat | String indicating the video format as it is represented in MATLAB, e.g., RGB24 | Yes | |
| Width | Width of the video frame in pixels | Yes |
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.
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);get (hgsetget), mmfileinfo, read (mmreader), set (hgsetget)
![]() | mmfileinfo | mmreader.isPlatformSupported | ![]() |

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 |