Clear Filters
Clear Filters

VideoReader with small mp4 files uses all memory

3 views (last 30 days)
I have an AVCHD video file, which I convert with handbrake into .mp4 file. Then I am trying to store the whole file into a structure array (it's an operation which I always do with other videos, and the code works just perfectly fine). But this time, with a (only) 125MB video, the memory of my laptop (I have 16GB!) increases very quicly and gets full, until I get the out of memory error. I also tried to convert the video to a lower (super low) quality and I got a 5MB file, but when reading it I have the same memory usage increase until it gets full. The curious thing is that I get the out of memory error when there is just 1 frame to read to finish.
There is clearly something wrong happening here, do you have any hint? I'm running MATLAB 2016b.
  3 Comments
Stefano Alois
Stefano Alois on 27 Feb 2017
vidObj = VideoReader(strcat(path1,file,mp4));
vidHeight = vidObj.Height;
vidWidth = vidObj.Width;
cama = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
'colormap',[]);
%Load frames in a structured data
a = 1;
while hasFrame(vidObj)
cama(a).cdata = readFrame(vidObj);
a = a+1
end
mp4 file size is 175392 Kb. Memory usage when loading the file is above 10Gb.
Walter Roberson
Walter Roberson on 27 Feb 2017
You are reallocating cama each time through the loop. You should determine how many frames you have, allocate cama as a struct with that many elements, and then go back and read the frames.
You will need to use the same basic framework of hasFrame to count the frames; the number-of-frames field is an estimate.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!