MatLab,如何预先分配帧来制作电影?
Matlab 有以下制作 avi 格式电影的指南。我的目标是能够通过 powerpoint 播放演示文稿中的视频。
nFrames = 20;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', [],...
'colormap', []);
% Create movie.
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
for k = 1:nFrames
surf(sin(2*pi*k/20)*Z,Z)
mov(k) = getframe(gcf);
end
% Create AVI file.
movie2avi(mov, 'myPeaks.avi', 'compression', 'None');
我理解这个示例,并且我不应该将压缩加载到 PowerPoint 中。但是我不明白如何使用 struct 正确地预分配内存。
Matlab has the following guide to making a movie in avi format. My goal is to be able to play the video in my presentation through powerpoint.
nFrames = 20;
% Preallocate movie structure.
mov(1:nFrames) = struct('cdata', [],...
'colormap', []);
% Create movie.
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
for k = 1:nFrames
surf(sin(2*pi*k/20)*Z,Z)
mov(k) = getframe(gcf);
end
% Create AVI file.
movie2avi(mov, 'myPeaks.avi', 'compression', 'None');
I understand this example and that I should have no compression to load into PowerPoint. However I dont understand how to properly preallocate my memory using struct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
avifile
来创建电影,甚至可以使用更新的VideoWriter
:avifile
VideoWriter
You could use
avifile
to create the movie or even the newerVideoWriter
:avifile
VideoWriter
您不需要预先分配。只需初始化
mov = []
即可。另外,getframe
假定gcf
,因此您可以只使用mov(k) = getframe()
。我同意你想要一个未压缩的视频。 Matlab 附带的编解码器非常有限。如果空间很重要,您可以使用开源工具来压缩视频。You don't need to pre-allocate. Just initialize
mov = []
. Alsogetframe
assumesgcf
, so you can just usemov(k) = getframe()
. I agree that you want an uncompressed video. The codecs that come with Matlab are pretty limited. You could use an open source tool to compress the video if space is important.您不必预先分配。它曾经帮助使用 moviein 命令进行预分配,但它不再提供任何性能改进。以下是 MATLAB 的引用:
You don't have to pre-allocate. It used to help to pre-allocate using moviein command, but it no longer provides any performance improvements. Here is the quote from MATLAB: