[英]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:由于您无法遵循该示例,因此以下是每行发生的情况的细分:
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).您可能想要使用一些属性,例如Quality
、 Duration
、 CompressionRatio
等)。curImage
L10 => 读取 png 文件并将其数据存储在变量curImage
中curImage
to the video file pointed by oVideo
L11 => 将 curImage 的内容添加到curImage
指向的视频文件oVideo
oVideo
) that was opened before L13 => 不要忘记关闭之前打开的视频文件( oVideo
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.