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正确地预分配我的记忆。
答案 0 :(得分:3)
您可以使用avifile
制作电影,甚至可以使用较新的VideoWriter
:
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
vid = avifile('myPeaks.avi', 'fps',15, 'quality',100);
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z)
vid = addframe(vid, getframe(gcf));
end
vid = close(vid);
winopen('myPeaks.avi')
Z = peaks; surf(Z);
axis tight
set(gca,'nextplot','replacechildren');
vid = VideoWriter('myPeaks2.avi');
vid.Quality = 100;
vid.FrameRate = 15;
open(vid);
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z)
writeVideo(vid, getframe(gcf));
end
close(vid);
winopen('myPeaks2.avi')
答案 1 :(得分:1)
您无需预先分配。只需初始化mov = []
即可。此外,getframe
还会使用gcf
,因此您只需使用mov(k) = getframe()
即可。我同意你想要一个未压缩的视频。 Matlab附带的编解码器非常有限。如果空间很重要,您可以使用开源工具压缩视频。
答案 2 :(得分:0)
您不必预先分配。它曾经帮助使用moviein命令进行预分配,但它不再提供任何性能改进。以下是MATLAB的引用:
var viewCon:UIViewController = self.presentingViewController!
self.dismissViewControllerAnimated(true, completion: {let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : VideoPlayViewController = storyboard.instantiateViewControllerWithIdentifier("video") as! VideoPlayViewController
vc.movieUrl = self.movieUrl
let navigationController = UINavigationController(rootViewController: vc)
viewCon.presentViewController(navigationController, animated: true, completion: nil)});