Main Content

hasFrame

Determine if video frame is available to read

Description

example

tf = hasFrame(v) returns logical 1 (true) if there is a video frame available to read from the file associated with v. Otherwise, it returns logical 0 (false).

Examples

collapse all

Create a VideoReader object for the sample video file xylophone_video.mp4.

v = VideoReader("xylophone_video.mp4");

Read all the frames from the video, one frame at a time.

while hasFrame(v)
    frame = readFrame(v);
end

Display information about the last frame returned by readFrame.

whos frame
  Name         Size                Bytes  Class    Attributes

  frame      240x320x3            230400  uint8              

Clear the VideoReader object.

clear v

Create a VideoReader object for the sample video file xylophone_video.mp4. Then determine the width and height of the video.

xyloObj = VideoReader("xylophone_video.mp4");
vidWidth = xyloObj.Width;
vidHeight = xyloObj.Height;

Create a video structure array.

mov = struct("cdata",zeros(vidHeight,vidWidth,3,"uint8"),colormap=[]);

Read one frame at a time until the end of the video.

k = 1;
while hasFrame(xyloObj)
    mov(k).cdata = readFrame(xyloObj);
    k = k+1;
end

Size a figure based on the width and height of the video, and then play the video one time.

vf = figure(Position=[0 0 xyloObj.Width xyloObj.Height]);
imshow(mov(1).cdata,Border="tight")
movie(vf,mov,1,xyloObj.FrameRate)

Clear the VideoReader object.

clear xyloObj

Input Arguments

collapse all

Input VideoReader object. Use the VideoReader function to create a VideoReader object from your video file.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2014b