Why is the "readFrames" function only reading half of my video frames?

5 vues (au cours des 30 derniers jours)
Jeroen Aeles
Jeroen Aeles le 23 Juin 2016
Hi,
I am trying to import a video file in Matlab and want them as "stacked images". If my video is for example 700 frames, I would like to end up with a structure (eg video_img) that has 700 separate images in it.
For some reason the function I am using only does the trick for half of the frames.
I am using:
v = VideoReader('TimeTest.MOV')
to import the video.
NrFrames = v.NumberOfFrames
To get the number of frames (in my example this gives NrFrames = 700. Then I generate a vector with letters for the structure
bla=char('a'+(1:26)-1)';
[I,J]=ndgrid(1:26,1:26);
I=I'; J=J';
XX=[bla(I(:)), bla(J(:))];
Then I try to read the video as separate frames using:
for frame = 1:NrFrames
videoframe.(char(XX(frame,:))) = read(v,frame);
end
or
i = 1
while hasFrame(v)
videoframe.(char(XX(i,:))) = readFrame(v,i);
i = i+1;
end
Both give me the same solution. I get an error at frame or i = 351 that reads:
"Error using VideoReader/read (line 160) The frame index requested is beyond the end of the file."
When I look at the frames, using:
i = 350
image(videoframe.(char(XX(i,:)))
It actually shows the last frame of the video... but this should be frame 700 and not 350? Can anyone please help me what I am doing wrong en why the frames I extract does not match (but is exactly half of) the actual number of frames? Does it have something to do with the samplingfrequency of the camera? Can Matlab only read at 30 fps or something like that?
Thanks in advance!
Jeroen
  1 commentaire
Walter Roberson
Walter Roberson le 2 Mai 2019
You cannot count on the NumberOfFrames property for any variable-rate movie. However, hasFrame() loop is expected to be correct.

Connectez-vous pour commenter.

Réponses (1)

jonah zimmerman
jonah zimmerman le 2 Mai 2019
Did you ever figure out a solution to this problem?
  1 commentaire
Armin Panjehpour
Armin Panjehpour le 17 Avr 2021
Did you ever found the solution to this problem?
Thanks for your answer

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by