Possible memory error using VideoWriter/writeVideo

7 views (last 30 days)
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

Answers (0)

Community Treasure Hunt

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

Start Hunting!