Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

read (mmreader) - Read video frame data from multimedia reader object

Syntax

video = read(obj)
video = read(obj, index)

Description

video = read(obj) reads in all video frames from the associated file. video is an H-by-W-by-B-by-F matrix where H is the image frame height, W is the image frame width, B is the number of bands in the image (e.g., 3 for RGB), and F is the number of frames read in. video contains uint8 data representing RGB24 video frames.

video = read(obj, index) reads only the frames specified by index, where the first frame number is 1. index can be a single index, or a two-element array representing an index range of the video stream.

For example:

video = read(obj, 1);         % first frame only
video = read(obj, [1 10]);    % first 10 frames
video = read(obj, Inf);       % last frame only
video = read(obj, [50 Inf]);  % frame 50 through end of file

For information about specifying the index in variable frame rate files, see mmreader.

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), mmreader, movie, 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