Posts Tagged ‘find frame rate in the given video using matlab’

Read frames from a given video using MATLAB code

Here is the code to read the frames from a given video using MATLAB. It is very easy to read the individual frames from a given video. The code as follows

function [ frame ] = readFrames( vid )

readerobj = mmreader(vid);
vidFrames = read(readerobj);
numFrames = get(readerobj, ‘numberOfFrames’);
for k = 1 : numFrames
mov(k).cdata = vidFrames(:,:,:,k);
mov(k).colormap = [];
imagename=strcat(int2str(k), ‘.jpeg’);
imwrite(mov(k).cdata, strcat(‘vasanth’,imagename));


mmreader() function supports more number of video format if you go for avireader() it allows only avi files. In the above code mov(k).cdata contains the actual image information. Using imwrite() we are actually writting the image on the harddisk. imagename=strcat(int2str(k), ‘.jpeg’); Here I’m appending the k.jpeg ex: 2.jpeg if you want to have in the other formats you can simply write .bmp or .jpg or .png instead of jpeg in the above code. vidFrames(:,:,:,k); returns the video frames.