Search code examples
matlabmemoryvideo-processing

Matlab: I have limited memory, are the alternate solutions for reading in data from a video?


I am currently having a problem with matlab in that when I try and read in some data from a video I am presented with an error:

??? Not enough memory available for 990 frames.

I have enough memory available for reading about 100 frames or so.

I say alternate solutions in the title as I would assume the obvious answer would be to buy more memory. Are there any other ways of reading these frames and processing them? For example I thought that perhaps I may be able to read in a frame at a time via a loop and resize the video frame in order to use less memory (or do this via an alternate program)? The video is pretty memory intensive at 1024x1024. However by downscaling I am worried that I will be losing valuable data from the video.

Any help would be greatly appreciated!

Thanks in advance :)

ps. Current code:

vid = VideoReader('video.avi');
frames = read(vid);

Solution

  • You can read spesific frame(s) by giving the indices instead of reading all of the frames into the memory as given in the documentation.

    frames = read(vid); %# Read all
    frames = read(vid, index); %# Read only the specified frames
    

    Example

    frames = read(vid, [1 50]); %# Read the first 50 frames