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

Thread Subject:
Loading video frame gets slower and slower

Subject: Loading video frame gets slower and slower

From: Peter Bone

Date: 1 Feb, 2012 15:23:10

Message: 1 of 6

I have a for loop and I'm loading and displaying a video frame from a video file each frame using mmread. I'm not pre-loading all the frames because it runs out of memory.
The time it takes to load the frame steadily increases as it runs. It starts out at around 1s and steadily goes up to around 2s after 100 frames.
Why is this happening? It's not related to the frame number in the video because if I start the frame loop at frame 100 then it starts from 1s loading time again. The loops doing the same thing each frame and overwriting the previous frame so I can't see why it slows down. Any ideas?
Is there an alternative that will let me load video into Matlab quickly without running out of memory?

Subject: Loading video frame gets slower and slower

From: Peter Bone

Date: 1 Feb, 2012 15:37:09

Message: 2 of 6

Found the problem. I wasn't clearing the figure axes after each frame so it was drawing all previous frame images each time. I'd still like to know if there are better ways of loading video since it still takes 1s to load each frame. Maybe it would be quicker to load video in through a simulink model and put my code into an s-function?

Subject: Loading video frame gets slower and slower

From: Suraj

Date: 1 Feb, 2012 16:03:09

Message: 3 of 6

How did you insert axes() function with your code? What if you use vision.videoplayer function, then how can I insert axes() function?

All I need is the output of vision.videoplayer, how can I insert onto GUI axes i've created, any idea?

Subject: Loading video frame gets slower and slower

From: Peter Bone

Date: 1 Feb, 2012 16:19:09

Message: 4 of 6

"Suraj " <suraj.kv.blog@gmail.com> wrote in message <jgbnnt$6lq$1@newscl01ah.mathworks.com>...
> How did you insert axes() function with your code? What if you use vision.videoplayer function, then how can I insert axes() function?
>
> All I need is the output of vision.videoplayer, how can I insert onto GUI axes i've created, any idea?

I just do

vid = mmread(filename, frame_num);
cla
imshow(vid.frames(1).cdata)

I don't have the vision package so I don't know about vision.videoplayer

Subject: Loading video frame gets slower and slower

From: Suraj

Date: 1 Feb, 2012 16:41:10

Message: 5 of 6

Do you know how can I place the output of a vision.videoplayer onto a GUI? Or any bar graph to place on the axes of a GUI using GUIDE?

And also share if you know "How to load video in through a simulink model and put my code into an s-function?"

Subject: Loading video frame gets slower and slower

From: witek@mathworks.com

Date: 1 Feb, 2012 17:01:02

Message: 6 of 6

Hi Peter,

vision.VideoFileReader might work for you. It's designed specifically to sequentially load one frame at a time. It's part of the Computer
Vision System Toolbox.

Witek

Peter Bone <peterbone@hotmail.com> wrote:
> I have a for loop and I'm loading and displaying a video frame from a video file each frame using mmread. I'm not pre-loading all the frames because it runs out of memory.
> The time it takes to load the frame steadily increases as it runs. It starts out at around 1s and steadily goes up to around 2s after 100 frames.
> Why is this happening? It's not related to the frame number in the video because if I start the frame loop at frame 100 then it starts from 1s loading time again. The loops doing the same thing each frame and overwriting the previous frame so I can't see why it slows down. Any ideas?
> Is there an alternative that will let me load video into Matlab quickly without running out of memory?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us