Why do I get an insufficient memory error using the READ method on a VideoWriter object in MATLAB 7.12 (R2011a) ?

I have an AVI file that is 30MB on disk and has 1727 frames of resolution 320x240. When I create a VideoWriter object and call the READ method with the command:
obj = VideoWriter(filename);
vid = read(obj);
I get the following error :
??? Not enough memory available for 1727 frames.
Error in ==> VideoReader.read at 72
videoFrames = read(getImpl(obj));
I am able read AVI files of upto 11 MB created in the exact same manner with no error.
I tried starting a new session of MATLAB and executing the above commands with no other variables in the workspace. I still obtain the same error.

 Réponse acceptée

The error message suggests that MATLAB does not have enough memory to load all the frames at the same time. To verify this, execute the memory command to check the number of bytes in contiguous memory avaliable to MATLAB using the MEMORY command.
memory
Next check the number of bytes occupied in MATLAB by a single frame from the same AVI file. Please note that this size is different from the size on disk.
When the entire video is loaded, it will approximately need (size of a frame)*(number of frames) bytes to load into MATLAB.
This complete chunk of memory may not be free the moment the READ command is executed which might lead to the " memory not available" error.
As a workaround, please read the frames one at a time or in smaller blocks using the second argument to the READ method as below:
filename ='sample.avi';
xyloObj = VideoReader(filename);
vid_1 = read(xyloObj,[ 1 20]); % reads the first 20 frames

Plus de réponses (0)

Produits

Version

R2011a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by