Error using Video Writer
이전 댓글 표시
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);
I have been trying for some hours and I have found a very general statement on what to do here: https://de.mathworks.com/matlabcentral/answers/229630-why-do-i-get-error-in-videowriter-as-error-using-videowriter-writevideo-frame-must-be-436-by-344-e
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.
댓글 수: 2
Sudheer Bhimireddy
2020년 8월 10일
Did you try limiting the axis or axis length based on your values?
Matthias Heindl
2020년 8월 10일
편집: Matthias Heindl
2020년 8월 10일
채택된 답변
추가 답변 (1개)
Sudheer Bhimireddy
2020년 8월 10일
Your code looks strange. Do you have 'hold on' before the loop?
Also if you have complete extents of your x,y variables, you can find the global maximums and use them with xlim and ylim as shown below.
fig = figure(1);
f = gcf;
f.Position=[100 100 1050 340]; % <-this will be figure window display size in pixels
f.PaperUnits='inches';
f.PaperPosition=[0 0 4 3]; %<-this will be print size, all the frames will have this size
for t = 1:time_iterations
clf;
hold on;
for 1:number_objects_1
surf(x,y,z,'red')
end
for 1:number_objects_3
surf(x,y,z,'blue')
end
...
xlim([x_min x_max]);
ylim([y_min y_max]);
end
댓글 수: 3
Matthias Heindl
2020년 8월 10일
Sudheer Bhimireddy
2020년 8월 10일
As long as your framesize is fixes, it should not matter. If the framesize is not fixed, the figure axis object might be trying to adjust the limits to include the objects. More than xlim and ylim; try the first five lines of my code and see what happens (note that I have moved your figure initiation line outside the loop). If you are still getting an error, try to attach two consecutive frames as pictures.
Matthias Heindl
2020년 8월 10일
카테고리
도움말 센터 및 File Exchange에서 Just for fun에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!