writeVideo
将视频数据写入到文件
说明
示例
将一个 RGB 图像写入采用无损压缩的 Motion JPEG 2000 文件。
创建一个包含来自示例静态图像 peppers.png
的数据的数组。
A = imread("peppers.png");
为新视频文件创建一个 VideoWriter
对象。使用 "Archival"
描述文件指定一个采用无损压缩的 Motion JPEG 2000 文件。
v = VideoWriter("myFile","Archival");
验证新文件的视频压缩类型。
v.VideoCompressionMethod
ans = 'Motion JPEG 2000'
打开 VideoWriter
对象进行写入,并将 A
中的图像数据写入文件。
open(v) writeVideo(v,A)
关闭 VideoWriter
对象。
close(v)
从示例索引图像文件 corn.tif
中读取图像和颜色图数据。
[X,map] = imread("corn.tif");
为新的索引 AVI 文件创建一个 VideoWriter
对象。
v = VideoWriter("myIndexed.avi","Indexed AVI");
将颜色图数据分配到 v
的 Colormap
属性。
v.Colormap = map;
打开 VideoWriter
对象进行写入。打开 v
后,您无法更改其属性。
open(v)
将 X
中的图像数据写入视频文件。
writeVideo(v,X)
关闭 VideoWriter
对象。
close(v)
创建要读取的对象并写入一个示例视频,然后打开 AVI 文件进行写入。
reader = VideoReader("xylophone_video.mp4"); writer = VideoWriter("transcoded_xylophone.avi","Uncompressed AVI"); writer.FrameRate = reader.FrameRate; open(writer);
读取和写入每一帧。
while hasFrame(reader) img = readFrame(reader); writeVideo(writer,img) end
清除 VideoReader
对象并关闭 VideoWriter
对象。
clear reader
close(writer)
设置坐标区和图窗属性,以生成视频帧。
Z = peaks; surf(Z); axis tight manual
set(gca,"NextPlot","replacechildren")
为输出视频文件创建 VideoWriter
对象并打开该对象以进行写入。
v = VideoWriter("peaks.avi");
open(v)
生成一组帧,从图窗中获取每个帧,然后将每一帧写入文件。
for k = 1:20 surf(sin(2*pi*k/20)*Z,Z) frame = getframe(gcf); writeVideo(v,frame) end
关闭 VideoWriter
对象。
close(v)
输入参数
输入 VideoWriter
对象。使用 VideoWriter
创建该对象。
表示灰度或 RGB 彩色图像的值,指定为二维、三维或四维数组:
对于单一灰度图像、单色图像或索引图像,
img
必须是二维的:高×宽。对于单一真彩色 (RGB) 图像,
img
是三维的:高×宽×3。对于一系列灰度图像,
img
是四维的:高×宽×1×帧数。文件中所有帧的高和宽必须一致。对于一系列 RGB 图像,
img
是四维的:高×宽×3×帧数。文件中所有帧的高和宽必须一致。
创建 AVI 或 MPEG-4 文件时:
img
是single
、double
或uint8
值的数组,代表一个或多个灰度或 RGB 彩色图像,writeVideo
将这些图像作为一个或多个 RGB 视频帧写入。single
或double
类型的数据必须位于范围[0,1]
中,写入索引 AVI 文件时除外。
创建 Motion JPEG 2000 文件时:
img
是uint8
、int8
、uint16
或int16
值的数组,表示一个或多个单色或 RGB 彩色图像。
数据类型: single
| double
| int8
| int16
| uint8
| uint16
帧数据,指定为表示单个帧的 1×1 结构体数组,或表示多个帧的 1×F
结构体数组。每个帧都包含两个字段:cdata
和 colormap
。frame
数组通常由 getframe
函数返回。
如果 colormap
不为空,则 cdata
的每个元素应为二维(高×宽)数组。文件中所有帧的高和宽必须一致。
colormap
最多可包含 256 个条目。colormap
的每个元素必须在 [0,1]
范围内。
当您创建一个 VideoWriter
对象时,profile
输入和 cdata
的大小确定 writeVideo
如何使用 frame
。
VideoWriter 对象的 profile | cdata 的每个元素的大小 | writeVideo 的行为 |
---|---|---|
| 二维(高×宽) | 使用所提供的帧。 |
'Grayscale AVI' | 二维(高×宽) | 使用所提供的帧。colormap 应为空。 |
所有其他描述文件 | 二维(高×宽) | 使用 colormap 字段构造 RGB 图像帧 |
三维(高×宽×3) | 忽略 colormap 字段。使用 cdata 字段构造 RGB 图像帧 |
数据类型: struct
版本历史记录
在 R2010b 中推出
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)