Create a .avi through VideoWriter

조회 수: 3 (최근 30일)
Richard Wood
Richard Wood 2020년 2월 24일
댓글: Richard Wood 2020년 2월 25일
Hello everyone,
I am trying to replicate the approach given in this example: https://es.mathworks.com/matlabcentral/answers/78345-make-a-smooth-animation
I want, as him, to not to show each frame in iteration of a loop, and get directly the .avi video. I have tried to addapt directly the code for my case, but it seems that avifile function does not work in my MatLab version (the last one). So I have seen that the role of avifile has been replaced by VideoWriter. The problem is... which function plays the role of addframe in the VideoWriter environment? I let you here my example of the code adapted directly from the aforementioned post
physical_time_inelastic=[0:1:30];
spatial_grid=[0:1:100];
data_set_inelastic=rand([length(spatial_grid),4,length(physical_time_inelastic)]);
avi_mx_inelastic=VideoWriter('mx_Magnetization_Component_Evolution_Inelastic.avi');
u9=figure('visible','off');
for i=1:length(physical_time_inelastic)
plot(spatial_grid.*(10^6),data_set_inelastic(:,2,i),'-b','LineWidth',2)
xlabel('Track position, $x \, \, \left( \mu\mathrm{m} \right)$','FontSize',14,'interpreter','latex')
ylabel('$x$-{\it th} magnetization components, $m_x$','FontSize',14,'interpreter','latex')
t9=title(['Inelastic collision, $t=$',num2str(physical_time_inelastic(i).*(10^(12))),' ps'],'FontSize',14,'interpreter','latex')
set(t9,'interpreter','latex','FontSize',12)
set(u9,'Units','Inches');
posu9=get(u9,'Position');
set(u9,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[posu9(3),posu9(4)])
avi_mx_inelastic=addframe(avi_mx_inelastic,u9);
end
avi_mx_inelastic=close(avi_mx_inelastic)
implay('mx_Magnetization_Component_Evolution_Inelastic.avi')
Also I would want to display in the title of each frame which is the value of physical_time_inelastic variable. It works as it is, but I would prefer the number to be in scientific notation. Any suggestion?
  댓글 수: 2
darova
darova 2020년 2월 24일
I can't run your code without data
Richard Wood
Richard Wood 2020년 2월 25일
See above that I have created the necessary matrices with random values, just to be used as an example.

댓글을 달려면 로그인하십시오.

채택된 답변

Delprat Sebastien
Delprat Sebastien 2020년 2월 25일
Well everything is in the doc and that's very easy. It is writeVideo.
Z = peaks; surf(Z); axis tight manual set(gca,'nextplot','replacechildren'); v = VideoWriter('peaks.avi'); open(v); for k = 1:20 surf(sin(2*pi*k/20)*Z,Z) frame = getframe(gcf); writeVideo(v,frame); end close(v);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by