| Contents | Index |
Create object for reading video files
Note mmreader will be removed in a future release. Use VideoReader instead. The mmreader class has been renamed VideoReader. |
Use mmreader with the read method to read video data from a multimedia file into the MATLAB workspace.
The file formats that mmreader supports vary by platform, as follows (with no restrictions on file extensions):
All Platforms | 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). |
For more information, see Supported Video File Formats in the MATLAB Data Import and Export documentation.
obj = mmreader(filename) constructs obj to read video data from the file named filename. The mmreader constructor searches for the file on the MATLAB path. If it cannot construct the object for any reason, mmreader generates an error.
obj = mmreader(filename,'PropertyName',PropertyValue) constructs the object using options, specified as property name/value pairs. Property name/value pairs can be in any format that the set method supports: name/value string pairs, structures, or name/value cell array pairs.
BitsPerPixel |
Bits per pixel of the video data. (Read-only) |
Duration |
Total length of the file in seconds. (Read-only) |
FrameRate |
Frame rate of the video in frames per second. (Read-only) |
Height |
Height of the video frame in pixels. (Read-only) |
Name |
Name of the file associated with the object. (Read-only) |
NumberOfFrames |
Total number of frames in the video stream. (Read-only) 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, use the read method to read the last frame of the file. For example: vidObj = mmreader('varFrameRateFile.wmv');
lastFrame = read(vidObj, inf);
numFrames = vidObj.NumberOfFrames;
For more information, see Reading Variable Frame Rate Video in the MATLAB Data Import and Export documentation. |
Path |
String containing the full path to the file associated with the reader. (Read-only) |
Tag |
User-defined string to identify the object. Default: '' |
Type |
Class name of the object: 'mmreader'. (Read-only) |
UserData |
Generic field for user-defined data. Default: [] |
VideoFormat |
String indicating the MATLAB representation of the video format, such as 'RGB24'. (Read-only) |
Width |
Width of the video frame in pixels. (Read-only) |
For backward compatibility, mmreader supports the following VideoReader methods:
| get | Query property values for video reader object |
| getFileFormats | File formats that VideoReader supports |
| isPlatformSupported | Determine whether VideoReader is available on current platform |
| read | Read video frame data from file |
| set | Set property values for video reader object |
Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB Programming Fundamentals documentation.
Construct an mmreader object for the demo movie file xylophone.mpg and view its properties:
xyloObj = mmreader('xylophone.mpg', 'Tag', 'My reader object');
get(xyloObj)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);| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |