| MATLAB® | ![]() |
video = read(obj)
video = read(obj, index)
video = read(obj) reads in 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. The default behavior is to read in all frames unless an index is specified. The type of data returned is always UINT8 data representing RGB24 video frames.
video = read(obj, index) performs the same operation, but reads only the frame(s) 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, read only the first frame:
video = read(obj, 1);
Read the first 10 frames:
video = read(obj, [1 10]);
You can use Inf to represent the last frame in the file:
video = read(obj, Inf);
Read from frame 50 through the end of the file:
video = read(obj, [50 Inf]);
If an invalid index is specified, the MATLAB software throws an error.
Construct a multimedia reader object associated with file xylophone.mpg and with the user tag property set to 'myreader1'.
readerobj = mmreader('xylophone.mpg', 'tag', 'myreader1');
Read in all video frames from the file.
vidFrames = read(readerobj);
Determine the number of frames in the file.
numFrames = get(readerobj, 'NumberOfFrames');
Create a MATLAB movie struct from the video frames.
for k = 1 : numFrames mov(k).cdata = vidFrames(:,:,:,k); mov(k).colormap = []; end
Create a figure.
hf = figure;
Resize the figure based on the video's width and height.
set(hf, 'position', [150 150 readerobj.Width readerobj.Height])
Play back the movie once at the video's frame rate.
movie(hf, mov, 1, readerobj.FrameRate);
![]() | rcond | readasync | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |