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 = [];
%imshow(mov(k).cdata);
imagename=strcat(int2str(k), ‘.jpeg’);
imwrite(mov(k).cdata, strcat(‘vasanth’,imagename));
%extractComponents(mov(k).cdata);end
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); writtens the vido frams.
great job,dude……….. i m working on video retrival mini project, but not getting, hw 2 detect boundary and index frames, could u help me plz?????/
There are different ways of extracting key frames. You can get many of research papers. I used similarity based key frame extraction.
Hi:
Nice work Man. I have recently started working on videos in matlab. I have a query regarding reading and writing videos in matlab. I hope you can help. Actually I want to perform following steps,
(1). Read simple colored video file in matlab.
(2). Extract frames in some structure.
(3). Convert frames to grayscale.
(4). Perform some operation on gray scale images.
(5). Make a video from processed gray scale images/frames.
(6). Write the video to harddisk.
Actually I am getting problem in step 5 and 6. I hope you can guide me in this regard. Anxiously waiting for your reply.
Regards
The following will work for you
Mov1(n) = im2frame(uint8(fg),gray);
movie2avi(Mov1,’mixture_of_gaussians_output’,'fps’,30); % save movie as avi
Great work. Thanks for sharing. Can you please share code for detecting vehicles in a Lane of video.
V.Neethidevan
neethidevan@gmail.com
Hi,
i used ur code to read the frames of video..i ended wit an error like tis……1st frame of an video is displayed…but not able to save as image…wat might b the pbm?????
??? Error using ==> imwrite at 457
Can’t open file “vasanth1.jpeg” for writing.
You may not have write permission.
Error in ==> readFrames at 11
imwrite(mov(k).cdata, strcat(‘vasanth’,imagename));
You may not have the write permission to write the frame into the current working directory. Check once.
hi,
can u plz help me to extract the I,P and B frames of mpeg2 video
regards
hai ehsan, i mentioned in your last command, you have the problem in 5th steps,. but i need the solution for first two step, pls give me the coding for step 1 and 2.
and i also request Mr.vasanth raja. to give me the coding for that one
hai ehsan, you mentioned in your last command, you have the problem in 5th steps,. but i need the solution for first two step, pls give me the coding for step 1 and 2.
and i also request Mr.vasanth raja. to give me the coding for that one
Hi vasanth
I tried to read a 32bit codec video in 64bit matlab. I get the error message like this
??? Initialization failed. (No combination of intermediate filters could be found to make the connection.)
Error in ==> mmreader.mmreader>mmreader.init at 423
obj.MMReaderImpl = audiovideo.mmreader(fullName);
Error in ==> mmreader.mmreader>mmreader.mmreader at 133
obj.init(fileName);
Can this problem be fixed using 64 bit matlab?
Yes.. I guess.. I did went through this kind of problems.. Just try out with 32 bit Matlab
Yes I guess.. I did not get this kind of problems.. Just try with 32 bit Matlab.
sir i want to compare the captured image with the image which i hav already stored….so pls could u help me
This Matlab code is helpful!
However the typical video I have has 3000 frames and I just need to look at a certain sequence of frames ( say from frames 1834 to frames 1875 ) so then how am I going to modify the above code?
Also how do I get information like the time between two frames ( frame rate ) in my case its 300fps or 3.33 ms between two adjacent frames.
good nice work
nice one..:)
hi, i need to extract the I,P and B frames of mpg video too could u help me, and how can we discrimintate between them, please help me?
regards
I am need of Matlab codes for my project “Query by Video clips”
hi , can pls help me i need matlab code for dividing(any format video) into frames i need it for project pls pls help me………
hi , can u pls help me…. i need matlab code for dividing(any format video) into frames i need it for project pls pls help me………
Hi all!
I am doing a project in which i have to take frames out of a running video and make them available for some function. I had run the code given above but I am getting an error written below. could any of you please tell reason for this error.
??? Undefined function or variable “vidFrames”
Error in ==> readFrames at 8
mov(k).cdata = vidFrames(:,:,:,k);
hi,
can u plz help me to extract the I,P and B frames from a video file in matlab.
regards
hi, i dnt knw how to use the cell and zeros func in matlab ..can u help me out…and here is my code..i am nt able to store required frames in a single array and use t ltr,,plz help me out.
vid=mmreader(‘ccc.avi’);
numFrames = vid.NumberOfFrames;
n=numFrames;
for i = 1:8:n
frames = read(vid,i);
imwrite(frames,[int2str(i) '.jpg']);
im(i)=image(frames);
figure,imshow(im(i));
end
hi, i have tried above code in matlab but Warning: Unable to determine the number of frames in this file.
hi, can u pls help me. i need a matlab code for video using mmreader. In this case, video stream is converted into number of frames. That frames are stored in separate folder. how to save the frames in folder using mmreader function?..pls help me
hi sir,
thank sir…but I need a code for read the frames that are stored in separate folder using mmreader function….pls can u help me sir?
Thanks for ur reply!!! I have alredy done dis much.. i am able to view images from frames seperately but m also not able to store them in a seperate foleder and them read them again so that they can become input for my another function.
nice code…
hi sir,I need a code for background subtraction using mmreader with a background reference image and current frame in video using matlab.In this case, number of frames that are stored in seperate folder?…pls help me sir
nice, i am doing project in dip i want to get animated gif image in matlab shall u help me
sir i want to convert video into image frames in matlab , so sir can you guide me.
I will be very thankful to you.
hai..i m working on video segmentation and summarization using genetic algorithm..can anyone suggest me a code for this topic?
suggest me a matlab code for video segmantation and summarization using genetic algorithm…
i am working on colorizatioin using optimization algorithm by anat levin.. i am not able to bring out an output for video colorization.. can i be assisted regarding that.. plzz. i can reachd over email at damodar27.ece@gmail.com
hi plz send me matlab code for extraction of key frames from a video
You can use the Matlab VideoUtils toolbox:
http://sourceforge.net/projects/videoutils/
It is very easy to use.
thanks for the code
I really am in need of help on another post i left for db linking with matlab and also on this… If u can please.
1. Getting frequency response(FFT) of audio file brought to matlab gui from db in ms access .
2. How do i show several plots for different frequencies(noises) in a single audio file in my GUI.
3. How do i show output of fol noises and show their frequency ranges on GUI:-
> humming
> human voices
> male
> female
> chirping of birds
> helicopters sounds including:-
>> engine
>> rotary wings
With many thanx in advance if u can help. Coz im not finding anything helpful otherwise. And m totally lost in doing above.:(
Many regards
Saima
I have to break a video into temporal sequences, and then select from each video sequence the most representative frame, and generate a hash based on local and global variables (texture, color histogram, etc), that I have to save in a database. I could use some help with any of the above. Thank you!
How to divide a .wav file into frames and place the frames in a matrix and access them later?
i am unable to run the code for video filtering for grayscale avi videos kindly help? where can i download color avi videos
Great work man
visit to get the code for extracting video frames from an avi file
http://matlabnstuff.blogspot.in/2013/01/extracting-frames-from-video-file.html
Motion detection full code given,visit : http://matlabnstuff.blogspot.in/2013/01/motion-detection-using-camshift.html