Possible memory error using VideoWriter/writeVideo

조회 수: 8 (최근 30일)
Mark Skopin
Mark Skopin 2014년 8월 12일
Hello All,
I am trying to change the frames per second (fps) of .avi files from 30 to 10 fps. The avi files were acquired and created with MATLAB, but unfortunately the correct fps was not written to the avi codec. The only way I have been successful in changing the fps is by creating a new avi and using the functions VideoWriter and writeVideo. This is not a problem with avi files less than ~300MB or 10,000 RGB frames at 640x480 pixels. However, I am receiving an error for files greater than this. The error message is: "Error using VideoWriter/writeVideo (line 408) Unexpected error". The code is below:
vid = VideoReader(vidFile);
[pathstr,filename] = fileparts(vidFile);
writerObj = VideoWriter([pathstr '\' filename '_fps']);
writerObj.FrameRate = newFPS;
open(writerObj);
nFrames = vid.NumberOfFrames;
vidHeight = vid.Height;
vidWidth = vid.Width;
grayIm(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 3,'uint8'),'colormap', []);
mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 1,'uint8'),'colormap', 'gray');
for k = 1 : nFrames
if k/100 == round(k/100) || k == 1
disp([num2str(k) '/' num2str(nFrames) ' ' datestr(now,'dd-mmm-yyyy HH:MM:SS')])
end
grayIm(k).cdata = read(vid, k);
mov(k).cdata = grayIm(k).cdata(:,:,1);
writeVideo(writerObj, mov(k).cdata);
end
close(writerObj);
I am using MATLAB version R2014a. I suspect that is a memory issue but I am not sure had to avoid this error, nor do I think DiskLogger would work because the avi is not be acquired just converted. However, I could be wrong about this.
I appreciate any help or insight in this matter.
Thanks in advance!
-Mark

답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by