在matlab中创buildvideo的方法

在Matlab中创buildvideo有什么可能? 我正在search,发现主要有3个工具箱,在这个领域的工作,image processing,图像采集和控制愿景……但我怎么能没有他们,只是从头开始创buildvideo? 我感兴趣的各种方法有一个概述,但我无法find任何体面的教程或互联网上的一致的信息来源。

谢谢您的帮助!

下面是在(核心)MATLAB中创build电影的一些不同的方法。

MOVIE2AVI

%# figure figure, set(gcf, 'Color','white') Z = peaks; surf(Z); axis tight set(gca, 'nextplot','replacechildren', 'Visible','off'); %# preallocate nFrames = 20; mov(1:nFrames) = struct('cdata',[], 'colormap',[]); %# create movie for k=1:nFrames surf(sin(2*pi*k/20)*Z, Z) mov(k) = getframe(gca); end close(gcf) %# save as AVI file, and open it using system video player movie2avi(mov, 'myPeaks1.avi', 'compression','None', 'fps',10); winopen('myPeaks1.avi') 

AVIFILE

(不推荐使用VIDEOWRITER)

 %# figure figure, set(gcf, 'Color','white') Z = peaks; surf(Z); axis tight set(gca, 'nextplot','replacechildren', 'Visible','off'); %# create AVI object nFrames = 20; aviobj = avifile('myPeaks2.avi', 'fps',10); %# create movie for k=1:nFrames surf(sin(2*pi*k/20)*Z, Z) aviobj = addframe(aviobj, getframe(gca)); end close(gcf) %# save as AVI file, and open it using system video player aviobj = close(aviobj); winopen('myPeaks2.avi') 

VIDEOWRITER

 %# figure figure, set(gcf, 'Color','white') Z = peaks; surf(Z); axis tight set(gca, 'nextplot','replacechildren', 'Visible','off'); %# create AVI object nFrames = 20; vidObj = VideoWriter('myPeaks3.avi'); vidObj.Quality = 100; vidObj.FrameRate = 10; open(vidObj); %# create movie for k=1:nFrames surf(sin(2*pi*k/20)*Z, Z) writeVideo(vidObj, getframe(gca)); end close(gcf) %# save as AVI file, and open it using system video player close(vidObj); winopen('myPeaks3.avi') 

IMWRITE

(技术上不是电影,而是一个animationGIF图像)

 %# figure figure, set(gcf, 'Color','white') Z = peaks; surf(Z); axis tight set(gca, 'nextplot','replacechildren', 'Visible','off'); %# preallocate nFrames = 20; f = getframe(gca); [f,map] = rgb2ind(f.cdata, 256, 'nodither'); mov = repmat(f, [1 1 1 nFrames]); %# create movie for k=1:nFrames surf(sin(2*pi*k/20)*Z, Z) f = getframe(gca); mov(:,:,1,k) = rgb2ind(f.cdata, map, 'nodither'); end close(gcf) %# create GIF and open imwrite(mov, map, 'myPeaks4.gif', 'DelayTime',0, 'LoopCount',inf) winopen('myPeaks4.gif') 

http://www.mathworks.de/help/techdoc/ref/videowriterclass.html

我的方法是使用printfunction打印单个帧/数字到PNG文件,给它们诸如1.png, 2.png, ...文件名,然后使用免费的FFMPEG转换器来制作video。

ffmpeg -r 20 -i %d.png foo.avi

当涉及到转换的参数(比特率,编解码器,几何等)时,这允许很多微调。

Matlab有一个内置的“电影”命令来播放电影。 我觉得这很容易处理。 我已经在情节中使用它来显示时间的变化,以及个人图像来制作真正的电影。

http://www.mathworks.com/help/techdoc/ref/movie.html

我相信一般程序是:

 for ii=1:100 plot(something(ii)) F = getframe; end movie(F) 

要保存一个电影,你可以使用类似的程序,但使用

 writeVideo 

命令。

http://www.mathworks.com/help/techdoc/ref/videowriterclass.html

QTWriter

要导出QuickTime影片,我可以使用我自己的QTWriter: http ://horchler.github.io/QTWriter/。 它与Matlab的VideoWriter类非常相似,但是同时具有有损和无损的静止图像编解码器(压缩格式),能够很好地处理Matlab绘图(即没有帧间压缩)中的典型数据。 值得注意的是,它还支持alpha通道透明度 ('Photo PNG'编解码器), 循环 (两种)和连续可变的帧速率 。 QTWriter是作为一个单独的Matlab类文件编写的,可以在所有平台上运行,但是我没有在Windows上testing过。

以下是一些示例代码,演示了如何生成一个简单的循环,可变的帧率QuickTime电影:

 % Prepare new movie file using the default PNG compression movObj = QTWriter('peaks.mov'); % Create an animation hf = figure; Z = peaks; surfc(Z); frames = 100; axis tight; set(hf,'DoubleBuffer','on'); set(gca,'nextplot','replacechildren'); % Animate plot and write movie for k = 0:frames hs = surfc(sin(2*pi*k/frames)*Z,Z); set(hs,'FaceColor','interp','FaceLighting','phong'); light('Position',[0 0 4]); movObj.FrameRate = k; % Vary the frame-rate writeMovie(movObj,getframe(hf)); % Write each frame to the file end movObj.Loop = 'backandforth'; % Set palindromic looping flag close(movObj); % Finish writing movie and close file 

输出电影,另一个更复杂的演示,进一步的细节可在项目网站上 。 QTWriter是开源的( BSD许可证 ),代码库在GitHub上 。