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

조회 수: 5 (최근 30일)
Jeroen Aeles
Jeroen Aeles 2016년 6월 23일
댓글: Armin Panjehpour 2021년 4월 17일
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
Walter Roberson
Walter Roberson 2019년 5월 2일
You cannot count on the NumberOfFrames property for any variable-rate movie. However, hasFrame() loop is expected to be correct.

댓글을 달려면 로그인하십시오.

답변 (1개)

jonah zimmerman
jonah zimmerman 2019년 5월 2일
Did you ever figure out a solution to this problem?

Community Treasure Hunt

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

Start Hunting!

Translated by