Search code examples
matlabcomputer-visionmatlab-cvst

How to determine number of frames using vision.VideoFileReader


I've got a video, how could I determine number of frames in the video using matlab built-in function - vision.VideoFileReader?

It is not the same as VideoReader which I can get the number of frames by :

vidObj = VideoReader('varFrameRateFile.wmv');
numFrames = vidObj.NumberOfFrames;

Solution

  • videoFReader = vision.VideoFileReader(FILENAME) 
    Frames = 0;
    while ~isDone(videoFReader)
      I = step(videoFReader);
      Frames = Frames+1;
    end
    

    Update : There is an alternative solution which does not require iteration over all frames in the video .

    videoSource2=VideoReader(FILENAME);
    frames=read(videoSource2);
    totalFrameNumber=size(frames,4);
    

    Hope this helps..