简体   繁体   English

从 Matlab 中的图像序列创建视频

[英]Creating a video from a sequence of images in Matlab

I am stuck on how to create an video file from from a sequence of images.我被困在如何从一系列图像中创建视频文件。

I have a folder with images as follows:我有一个包含以下图像的文件夹:

image01.png 
image02.png 
... 
image150.png

How do I combine them to a video in Matlab?如何将它们组合到 Matlab 中的视频中?

I saw this link explaining it, but I could not understand it exactly.我看到这个链接解释它,但我不能完全理解。

You may want to do something like this:你可能想做这样的事情:

nImage = 150;                                                        % L1
fps = 3.0;                                                           % L2
addToInFolder = 'Address\to\Input\Images\Folder';                    % L3
addToOutFolder = 'Address\to\Output\Video\Folder';                   % L4

oVideo = VideoWriter(fullfile(addToOutFolder, 'myVideo.avi'));       % L5
oVideo.FrameRate = fps;                                              % L6
open(oVideo)                                                         % L7
for i = 1:nImage                                                     % L8
    fname = ['image' num2str(i, '%.2d') '.png'];                     % L9
    curImage = imread(fullfile(addToInFolder,fname));                % L10
    writeVideo(oVideo, curImage);                                    % L11
end                                                                  % L12
close(oVideo)                                                        % L13

Since you could not follow the example, here is a break down of what is going on per line:由于您无法遵循该示例,因此以下是每行发生的情况的细分:

  • L1 => Total number of images which based on your file names is 150 L1 => 基于您的文件名的图像总数为 150
  • L2 => Frame per second of the movie you are making L2 => 您正在制作的电影的每秒帧数
  • L3 => Address to the input folder of your images L3 => 图像输入文件夹的地址
  • L4 => Address to the output folder for your movie L4 => 电影的 output 文件夹的地址
  • L5 => Create a complete address to the output movie (.avi) file and make a video file at this address to be written L5 => 为output电影(.avi)文件创建一个完整的地址,并在该地址制作一个视频文件写入
  • L6 => Set frame rate of the movie to fps . L6 => 将电影的帧速率设置为fps FrameRate is a property of a video object. FrameRate是视频 object 的属性。 See this page for the complete list of properties you can play with.有关您可以使用的属性的完整列表,请参阅此页面 There are properties you may want to play with like Quality , Duration , CompressionRatio , etc).您可能想要使用一些属性,例如QualityDurationCompressionRatio等)。
  • L7 => Video file needs to be opened to allow for writing data, otherwise you do not have the permission to write to this file L7 => 视频文件需要打开才能写入数据,否则你没有权限写入这个文件
  • L8 => Let's begin a loop over each image and make a frame out of it L8 => 让我们在每个图像上开始循环并从中制作一个框架
  • L9 => Create a string of file name for the current image (image01.png, ...., image150.png) L9 => 为当前图像创建一个文件名字符串 (image01.png, ...., image150.png)
  • L10 => Read the png file and store its data in variable curImage L10 => 读取 png 文件并将其数据存储在变量curImage
  • L11 => Add contents of curImage to the video file pointed by oVideo L11 => 将 curImage 的内容添加到curImage指向的视频文件oVideo
  • L13 => Don't forget to close the video file ( oVideo ) that was opened before L13 => 不要忘记关闭之前打开的视频文件( oVideo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM