Using writeVideo in 2015

6 visualizaciones (últimos 30 días)
Wyatt Culler
Wyatt Culler el 7 de Jul. de 2015
Comentada: Wyatt Culler el 13 de Jul. de 2015
I wrote a function in Matlab 2013 for my lab group that automates the process of making a .mp4 movie from a figure. The issue I have now is that while it works fine in 2013 it no longer works in Matlab 2015. Depending on the complexity of the figure I'm trying to make Matlab 2015 becomes unresponsive around 300 frames of an 8000 frame movie and eventually crashes with a
java.lang.OutOfMemoryError: Java heap space
error. Increasing the heap size for Matlab 2015 from 196 MB (the size I use in 2013) to 2112 MB lets the program run longer before crashes but it still crashes. I can copy the exact same script from Matlab 2015 that crashes and run it in Matlab 2013 and have no issues. Is there a known memory issue with using getframe() or writeVideo() in Matlab 2015? Right now my workaround is to use the older version of Matlab when I need to make longer movies but as my labmates' computers get upgraded I won't be able to do this. The function I'm using is below.
Thanks,
Wyatt
function writerObj=MakeMPEG_V2(loopiter,numframes,savefile,framerate,writerObj)
%Wyatt Culler 6/24/2015
%This function must be called in a loop in order to write an MP4 movie file.
%Required inputs are the figure handle, the loop iteration, and the save file.
%The optional argument is framerate which by default is 30.
%Note: This function overwrites old files without warning!
%Does not work in 2015
%Example Use
% clear
% clc
%
% startframe=1;
% endframe=300;
% numframes=endframe-startframe+1;
% framerate=30;
% global writerObj;
% savefile='yoursavefile';
% h1=figure;
% loopiter=0;
% for n=startframe:endframe
% loopiter=loopiter+1;
%
% clf
% hold on
% %######################################################################
%
% Put plot code here!
%
% %######################################################################
% writerObj=MakeMPEG_V2(loopiter,numframes,savefile,framerate,writerObj);
% end
% close(writerObj)
if exist('framerate','var')==0
framerate=15;
disp('Warning: Default of 15 frames/sec is being used!')
end
if loopiter==1;
writerObj=VideoWriter(strcat(savefile,'.mp4'),'MPEG-4');
writerObj.FrameRate=framerate;
open(writerObj)
elseif loopiter<=numframes
drawnow
frame=getframe(gcf);
writeVideo(writerObj,frame);
end
end
  2 comentarios
Dinesh Iyer
Dinesh Iyer el 7 de Jul. de 2015
Wyatt,
As you mentioned, you need to determine if the issue is with getFrame() or writeVideo. To test this, can you try the following?
1. Remove the video writing from your code and verify the just calling getFrame(gcf) results in the OutOfMemory error?
2. Restore writeVideo and remove the call to getFrame(). Just use some dummy data such as zeros(1080, 1920, 3) to test whether video writing is the culprit.
Dinesh
Wyatt Culler
Wyatt Culler el 13 de Jul. de 2015
Hi Dinesh,
Thank you for the troubleshooting suggestion. It seems like the larger issue is with getFrame(). Although I do not get the out of memory error when I only use getFrame() my iteration speed slows down significantly beyond 2000 frames and becomes unresponsive after about 2500 frames. In addition, my CPU usage climbs to between 95% and 100% as indicated by task manager. When I only use videoWriter, my iteration speed slows down around frame 4000 but does not become unresponsive. Are there alternatives to using getFrame() to make movies?
Thanks,
Wyatt

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by