Using writeVideo in 2015
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Dinesh Iyer
2015년 7월 7일
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!