This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

hasFrame

Determine if frame is available to read

Syntax

tf = hasFrame(v)

Description

example

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

Examples

collapse all

Create a VideoReader object for the example movie file, xylophone.mp4.

v = VideoReader('xylophone.mp4');

Read all video frames.

while hasFrame(v)
    video = readFrame(v);
end
whos video
  Name         Size                Bytes  Class    Attributes

  video      240x320x3            230400  uint8              

Read and play back the sample movie file, xylophone.mp4.

Create a VideoReader object to read data from the sample file. Then, determine the width and height of the video.

xyloObj = VideoReader('xylophone.mp4');

vidWidth = xyloObj.Width;
vidHeight = xyloObj.Height;

Create a movie structure array, mov.

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

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

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. Then, play back the movie once at the video frame rate.

hf = figure;
set(hf,'position',[150 150 vidWidth vidHeight]);

movie(hf,mov,1,xyloObj.FrameRate);

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™.

Introduced in R2014b