Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading and displaying video file frame by frame

Tags:

video

matlab

I am newly working with Matlab. I want to read a video file and do some calculations every frame and display every frame. I wrote the following code but every time it only displays the first frame. can anybody please help.

mov=VideoReader('c:\vid\Akiyo.mp4');
nFrames=mov.NumberOfFrames;
for i=1:nFrames
  videoFrame=read(mov,i);
  imshow(videoFrame);

end
like image 446
MMH Avatar asked Mar 21 '13 03:03

MMH


People also ask

When reading a video file simply which method is used to obtain frames per second?

Common property we may want to know, frame rate or frames per second, is discussed in detail. When reading a video file simply use the get method to obtain frames per second.


1 Answers

Note: mmreader API has been discontinued by MATLAB so prefer using VideoReader.

See comment by @Vivek.

I usually do this:

obj=mmreader('c:\vid\Akiyo.mp4');
nFrames=obj.NumberOfFrames;
for k=1:nFrames
    img=read(obj,k);
    figure(1),imshow(img,[]);
end

As far as your code is concerned, I saw MATLAB's documentation. You should do the things in following order:

mov=VideoReader('c:\vid\Akiyo.mp4');
vidFrames=read(mov);
nFrames=mov.NumberOfFrames;
for i=1:nFrames
   imshow(vidFrames(:,:,i),[]);  %frames are grayscale
end
like image 136
Autonomous Avatar answered Sep 22 '22 14:09

Autonomous