| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
Read video frame data from multimedia reader object
video = read(obj)
video = read(obj, index)
video = read(obj) reads in all video frames from the file associated with obj.
video = read(obj, index) reads only the specified frames. index can be a single number or a two-element array representing an index range of the video stream.
obj |
Name of multimedia object created with mmreader. |
index |
Frames to read, where the first frame number is 1. Use Inf to represent the last frame of the file. 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 thru end MATLAB cannot determine the number of frames in a variable frame rate file until you read the last frame. If the requested index extends beyond the end of the file, read returns either a warning or an error. For more information, see Reading Variable Frame Rate Video in the MATLAB Data Import and Export documentation. Default: [1 Inf] |
video |
Array of uint8 data representing RGB24 video frames. The dimensions are H-by-W-by-B-by-F, where:
|
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);
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |