フィルターのクリア

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