missing frames in mp4

The attached movie-file has about 38 frames. I can see them with VLC and with MPC-HC. Frames are 20ms appart as seen in the timestamps at the bottom of each image. Matlab however, only shows half of these frames every 40ms. How can I get all frames?

Answers (1)

YT
YT on 31 Oct 2018
From the documentation on VideoReader
v = VideoReader('stefan.mp4');
currAxes = axes;
while hasFrame(v)
vidFrame = readFrame(v);
image(vidFrame, 'Parent', currAxes);
currAxes.Visible = 'off';
pause(1/v.FrameRate);
end
More info on VideoReader can be found here

7 Comments

I don't see how this is different to my code.
v = VideoReader('stefan.mp4'); vidFrame = readFrame(v);
just doesn't do it. It's missing half the frames. somehow there have to be options for interlace/deinterlace videos.
Did you find a solution for this issue? I'm having the same problem
sadly no. It seems impsossible with Matlab. I'm using ffmpeg and separate the video into single images.
% make jpgs of mp4 file via ffmpeg. download together with k-lite codec
% pack. -qscale:v 2 maximizes jpg-quality
ffmpegfile = 'C:\Program Files\ffmpeg-4.2.1-win64-static\bin\ffmpeg';
str = sprintf('\"%s" -i \"%s\" -qscale:v 2 \"%s\\%s_%%03d.jpg\" -hide_banner', ...
ffmpegfile, file, PathName, FileName);
system(str);
Hello Stefan, thanks for the quick response. I have downloaded the example file you provided and even with VLC I am only seeing specific frames every 40 ms as well...
In my case, the videos are interlaced and Matlab only shows one of the two fields, but VLC does show the interlaced frames. The solution I found so far is to convert the files using another software like Prism. When I do that, then Matlab correctly reads the interlaced frames. The issue seems to come from the way the video is encoded, and the way Matlab and other softwares decode it, I guess...
yeah, those video codecs seem quite tricky. I use the media player classic (MPC) and there you see the single frames every 20ms in my example video. also when using the ffmpeg you see the 20ms timestamps in the single jpg-pictures.
It hasn't always been a problem. in this legacy SW im supporting obviously it was possible with the matlab internal video ddecoder. It just doesn't work like this way anymore after 10 or 20 years.
also, if MPC and VLC deliver different results, how could Matlab possibly chose the right way to decode the video. the solution seems not to be unique..
I have done some research, it appears one codec that is problematic is the Motion JPEG (MJPG or MJPEG). I have not tested all of them of course, and it seems I cannot get information on the file you provided on Matlab for some reason, so I don't know if it is encoded in MJPEG, but if that is the case, then that could explain why Matlab only reads half the frames. I have checked again and VLC does correctly read the interlaced frames on this file.
I had a similar problem, I changed from mp4 to AVI and now I can see all my frames. The size of the video tripled, but I have all the frames.

Sign in to comment.

Products

Release

R2015b

Community Treasure Hunt

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

Start Hunting!