MATLAB Answers

readFrame is only reading half of of my video frames

조회 수: 2(최근 30일)
Armin Panjehpour
Armin Panjehpour 2021년 4월 17일
편집: Armin Panjehpour 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
  댓글 수: 1
Armin Panjehpour
Armin Panjehpour 2021년 4월 17일
Thanks a lot!
Yes matlab was detecting the frame rate of the video, 15 FPS. I used an external software and rendered the video again in 30 FPS and matlab detect it right this time.
Thanks again :)

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by