MATLAB: Error using Video Writer

animationerrorframe sizeframesMATLABvideowriterwritevideo

Hey there,
I work on doing a simplified thermodynamic animation and I use the Video Writer object to accomplish that.
writeVideo requires each frame to be the exact same size. My frames are not. The reason for that may simply be, that it's a three dimensional simulation.
Is there a way, I can unify or fix the size for each frame?
The plot is created by using the 'surf' command and the 'patch' command. Since it's quite some lines of code, I decided not to share it here.
avi_video = VideoWriter('process_1.avi');
open(avi_video);
allTheFrames = cell(timeframes,1);
allTheFrames(:) = {zeros(vidHeight, vidWidth, 3, 'uint8')};
allColorMaps = cell(timeframes,1);
allColorMaps(:) = {zeros(256, 3)};
recalledmie = struct('cdata', allTheFrames, 'colormap', allColorMaps);
F_cell = struct2cell(F);
thisFirstFrame = cell2mat(F_cell(1, 1, calculations_per_frame));
continue_counter = 0;
for frame = 1 : timeframes
thisFrame = cell2mat(F_cell(1, 1, frame * calculations_per_frame));
if any(size(thisFrame) ~= size(thisFirstFrame))
continue_counter = continue_counter + 1;
continue
end
recalledmie(frame) = im2frame(thisFrame);
writeVideo(avi_video, thisFrame);
end
close(avi_video);
Furthermore I tried to work my way around that problem by setting up an if condition (Is the size of the current frame equal to the size of the first frame, and if not 'continue'), but too many frames seem to be of a slightly different size. I was not able to get a proper video from that.

Best Answer

If your subsequent images are not the same size as the first frame, you could call imresize() to make them the same size.
Related Question