video = read(obj)
video = read(obj,index)
video = read(___,'native')
video = read(obj) reads in all video frames from the file associated with obj. The read method returns a H-by-W-by-B-by-F matrix, video, where H is the image frame height, W is the image frame width, B is the number of bands in the image (for example, 3 for RGB), and F is the number of frames read.
video = read(___,'native') returns data in the format specified by the VideoFormat property, and can include any of the input arguments in the previous syntaxes.
Name of multimedia object created with VideoReader.
Frames to read, where the first frame number is 1. Use Inf to represent the last frame of the file.
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 Read Variable Frame Rate Video.
Default: [1 Inf]
Array of data representing video frames, returned in a format dependent on the VideoFormat property of obj. For most files, the data type and dimensions of video are as follows. Note that when the VideoFormat property of obj is 'Indexed', the data type and dimensions of video depend on whether you call read with the 'native' argument.
H is the image frame height, W is the image frame width, and F is the number of frames read.
For Motion JPEG 2000 files, the data type and dimensions of video are as follows.
Read and play back the movie file xylophone.mp4.
xyloObj = VideoReader('xylophone.mp4'); nFrames = xyloObj.NumberOfFrames; vidHeight = xyloObj.Height; vidWidth = xyloObj.Width;
Preallocate the 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);