readFrame is only reading half of of my video frames

조회 수: 15 (최근 30일)
Armin Panjehpour
Armin Panjehpour 2021년 4월 17일
답변: LO 2021년 4월 17일
v=VideoReader('crosswalk.mp4');
NrFrames = v.NumFrames % this one gives me 450 frames
t=0;
while hasFrame(v)
I = readFrame(v);
t=t+1;
end
% but the variable t gives me 225 frames
I`m using the code below to read the number of frames of my video but when I use readFrame it will cound half of my frames which is 225 but the total number of frames is 450 which v.NumFrames gives.
I`ve attached my video too. MY video
I really appreciate your support. Thanks

채택된 답변

LO
LO 2021년 4월 17일
it is probably because the frame rate of the video is detected as 15 fps
v=VideoReader('crosswalk.mp4');
t=0;
while hasFrame(v)
I = readFrame(v);
t=t+1;
end
duration = t/v.FrameRate % frames /fps = sec
you could do 2 things
either run another script to convert the frame rate of your video (basically use videowrite, set the right number of frames, load frame by frame and write each from to a new video... or try using some external software to correct the frame rate reading (ffmpeg could work).
I guess matlab is fine but simply the video info is read wrongly.
I found someone having had the same issue
see if it helps
https://www.mathworks.com/matlabcentral/answers/106048-problem-for-read-frame-of-video-clip-mp4

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by