필터 지우기
필터 지우기

VideoReader with small mp4 files uses all memory

조회 수: 3 (최근 30일)
Stefano Alois
Stefano Alois 2017년 2월 24일
댓글: Walter Roberson 2017년 2월 27일
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
Stefano Alois
Stefano Alois 2017년 2월 27일
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 2017년 2월 27일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by