MATLAB Answers


How to save video frames in another matlab file without making them visible

Asked by Beenish Mazhar on 28 Dec 2012

I have a video and I am doing some processing on the frames of video in matlab. After that the frames are compiled and a video is made by using those processed frames. There are about 300 frames in the video. As processing is quite heavy so my computer freezes. I just don't want to show those processed frames rather I want that those frames should be stored in another mfile. I know the commands like saveas or set(gcf,'visible','off') but they don't work in my case. What I have so far:

            aviobj =avifile('trail.avi','Compression','None','fps',1); 
            %video to be made from frames
            obj = aviread('highwayvideo.avi');
             for 1:300
            .......... % processing
            imi = getframe(gcf);
            aviobj = addframe(aviobj,imi);
            aviobj = close(aviobj);

Any help would be highly appreciated.


1 Answer

Answer by Image Analyst
on 28 Dec 2012
 Accepted answer

Use VideoReader() and read(). There's no requirement for you to display the image after you read it in. But that's not the real problem. 300 frames is not that many. The real reason why it gets slower and slower as it goes on is because you're displaying it in the same container (an axes control) without clearing out the axes, so all 300 frames are trying to get stuffed into it. You'll find it runs much faster if you do "cla reset" right before each call to imshow() or image().


Have an axes for each one. Create them in GUIDE. Then in the code:


Sir I have never used GUIDE. Can you kindly explain that how can I use GUIDE to implement the above mentioned code.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!