VideoWriter
Write video files
描述
VideoWriter
对象允许您从数组或MATLAB创建视频文件®电影。
You can use theVideoWriter
用预定义的功能profile创建一个VideoWriter
具有针对特定格式的属性的对象,例如'Uncompressed AVI'
or'MPEG-4'
。创建对象后,您可以使用点符号查看或修改特定属性:
v = videowriter('newfile.mj2',“运动JPEG 2000”);v.compressionratio = 3;
打开视频fi之前修改属性值le for writing. After you call the打开
function, you cannot change the value of a property.
创建
CreateVideoWriter
objects using theVideoWriter
function.
特性
色彩渠道
—颜色频道的数量
正整数
此属性仅阅读。
每个输出视频框架中的颜色通道数,指定为一个正整数:
未压缩的AVI,Motion JPEG AVI和MPEG-4文件具有三个颜色通道。
Indexed and grayscale AVI files have one color channel.
对于Motion JPEG 2000文件,频道的数量取决于输入数据
写入
功能:单色图像数据之一,三个用于颜色数据。
数据类型:双倍的
Colormap
—视频文件的颜色信息
P
-by-3数字矩阵
视频文件的颜色信息,指定为具有三列和最多256行的数字矩阵。矩阵中的每一行都使用RGB三重态定义一种颜色。RGB三重态是一个三元素行矢量,其元素指定了颜色的红色,绿色和蓝色组件的强度。强度必须在范围内[0,1]
。
You can set the colormap explicitly before the call to打开
,或使用colormap
field of a movie frame structure at the time of writing the first frame.
这Colormap
property only applies to objects used for writing indexed AVI files.
例子:colormap(summer(256))
数据类型:双倍的
|UINT8
CompressionRatio
—Target compression ratio
10
(默认)|整数大于1
目标压缩比,指定为大于1的整数。压缩比是输入图像中的字节数与压缩图像中的字节数之间的比率。视频数据尽可能被压缩到指定目标。
CompressionRatio
仅适用于编写运动JPEG 2000文件的对象。后你叫打开
,你不能更改CompressionRatio
价值。If you previously setLosslessCompression
到true
, settingCompressionRatio
generates an error.
例子:5
数据类型:单身的
|双倍的
|int8
|INT16
|INT32
|INT64
|UINT8
|UINT16
|UINT32
|Uint64
Duration
—Duration of output file
标量value
此属性仅阅读。
Duration of the output file in seconds, specified as a scalar value.
数据类型:双倍的
文件格式
—要写的文件类型
'avi'
|'mp4'
|'MJ2'
此属性仅阅读。
要编写的文件类型,指定为'avi'
,'mp4'
, 或者'MJ2'
。
Filename
—Name of file
角色向量
此属性仅阅读。
Name of file, specified as a character vector.
数据类型:char
FrameCount
—帧数
integer
此属性仅阅读。
帧数written to the video file, specified as an integer.
数据类型:双倍的
FrameRate
—视频播放速度
30
(默认)|正数
视频播放速度in frames per second, specified as a positive number.
后你叫打开
,你不能更改FrameRate
价值。
例子:10
数据类型:单身的
|双倍的
|int8
|INT16
|INT32
|INT64
|UINT8
|UINT16
|UINT32
|Uint64
Height
—Height of each video frame
标量
此属性仅阅读。
每个视频框架的高度在像素中,指定为标量。这写入
method sets values forHeight
andWidth
基于第一帧的尺寸。
MPEG-4文件需要框架尺寸,这些尺寸可除以两个。如果MPEG-4文件的输入帧高度不是偶数号码,则VideoWriter
pads the frame with a row of black pixels at the bottom. For MPEG-4 files on Windows®系统,允许的值取决于Windows的版本。例如,在Windows 10上允许Height
is in the range[34,2160]
。
数据类型:双倍的
LosslessCompression
—Lossless compression
true
|false
Lossless compression, specified astrue
orfalse
。这LosslessCompression
属性仅适用于编写运动JPEG 2000文件的对象。
IfLosslessCompression
istrue
,那么:
这
写入
函数写入数据,使解压缩数据与输入数据相同。VideoWriter
忽略任何指定的值CompressionRatio
。
后你叫打开
,你不能更改LosslessCompression
价值。
默认情况下,LosslessCompression
isfalse
for the“运动JPEG 2000”
profile andtrue
for the'Archival'
概要文件。
数据类型:logical
MJ2BitDepth
—Bit depth for Motion JPEG 2000 files
整数[1,16]
Bit depth for Motion JPEG 2000 files, specified as an integer in the range[1,16]
。这bit depth is the number of least-significant bits in the input image data
MJ2BitDepth
仅适用于编写运动JPEG 2000文件的对象。如果您在调用该值之前不指定值打开
方法,VideoWriter
sets the bit depth based on the input data type. For example, if the input data to写入
is an array ofUINT8
orint8
values, thenMJ2BitDepth
is8
。
例子:8
数据类型:单身的
|双倍的
|int8
|INT16
|INT32
|INT64
|UINT8
|UINT16
|UINT32
|Uint64
Path
—视频文件的完整路径
角色向量
此属性仅阅读。
视频文件的完整路径,指定为字符向量。
数据类型:char
质量
—Video quality
75
(默认)|整数[0,100]
Video quality, specified as an integer in the range,[0,100]
。Higher quality numbers result in higher video quality and larger file sizes. Lower quality numbers result in lower video quality and smaller file sizes.
质量
仅适用于与MPEG-4
orMotion JPEG AVI
概要文件。后你叫打开
,你不能更改质量
价值。
例子:50
数据类型:单身的
|双倍的
|int8
|INT16
|INT32
|INT64
|UINT8
|UINT16
|UINT32
|Uint64
VideoBitsperpixel
—Number of bits per pixel
numeric scalar
此属性仅阅读。
Number of bits per pixel in each output video frame, specified as a numeric scalar.
AVI files with truecolor video, Motion JPEG AVI, and MPEG-4 files have 24 bits per pixel (8 bits for each of three color bands).
索引和灰度avi文件每个像素有8位。
For Motion JPEG 2000 files, the number of bits per pixel depends on the value ofMJ2BitDepth
and the number of bands of image data. For example, if the input data to写入
is a three-dimensional array ofUINT16
orINT16
values, the default value ofMJ2BitDepth
is16
, andVideoBitsperpixel
is48
(three times the bit depth).
数据类型:双倍的
VideoCompressionMethod
—视频压缩类型
'没有任何'
|'H.264'
|“运动jpeg'
|“运动JPEG 2000”
此属性仅阅读。
视频压缩类型,指定为'没有任何'
,'H.264'
,“运动jpeg'
, 或者“运动JPEG 2000”
。
数据类型:char
videoformat
—MATLABrepresentation of video format
角色向量
此属性仅阅读。
视频格式的MATLAB表示,指定为字符向量。
For file types other than Motion JPEG 2000 files,videoformat
是以下内容之一。
视频格式 |
Value of |
---|---|
未压缩的AVI,运动JPEG AVI或MPEG-4文件 |
'RGB24' |
AVI files with indexed video |
'索引' |
带有灰度视频的AVI文件 |
“灰度” |
For Motion JPEG 2000 files,videoformat
取决于价值MJ2BitDepth
and the format of the input image data to the写入
method. For example, if you do not specify theMJ2BitDepth
property,VideoWriter
sets the format as shown in this table.
Format of Image Data |
Value of |
---|---|
Single-bandUINT8 |
'Mono8' |
Single-bandint8 |
'Mono8 Signed' |
Single-bandUINT16 |
'mono16' |
Single-bandINT16 |
'Mono16 Signed' |
三个伴侣UINT8 |
'RGB24' |
三个伴侣int8 |
'RGB24 Signed' |
三个伴侣UINT16 |
'RGB48' |
三个伴侣INT16 |
'RGB48 Signed' |
Width
—每个视频框架的宽度
numeric scalar
此属性仅阅读。
每个视频框架的宽度以像素为单位,指定为数字标量。这写入
function sets values forHeight
andWidth
基于第一帧的尺寸。
MPEG-4文件需要框架尺寸,这些尺寸可除以两个。If the input frame width for an MPEG-4 file is not an even number, thenVideoWriter
沿右侧用黑色像素列将框架垫板。对于Windows系统上的MPEG-4文件,允许的值取决于Windows的版本。例如,在Windows 10上允许Width
is in the range[34,3872]
。
数据类型:双倍的
Object Functions
打开 |
Open file for writing video data |
close |
关闭file after writing video data |
写入 |
Write video data to file |
VideOwriter.getProfiles |
Profiles and file formats that VideoWriter supports |
例子
创建VideoWriter对象并写视频
Create aVideoWriter
object to write a Motion JPEG AVI file namednewfile.avi
。
v = videowriter('newfile.avi');
Open the file for writing and write a 300-by-300 matrix of data to the file.
打开(v)写入(v,rand(300))
关闭the file.
关闭(v)
Specify Profile for Uncompressed AVI and Write Video
Create an array containing data from the sample still image,peppers.png
。
a = imread('peppers.png');
Create aVideoWriter
object for a new uncompressed AVI file for RGB24 video.
v = videowriter('newfile.avi','Uncompressed AVI');
Open the file for writing.
打开(v)
Write the image inA
到the video file.
写入(v,A)
关闭the file.
关闭(v)
Create AVI File from Animation
Write a sequence of frames to a compressed AVI file namedpeaks.avi
。
准备新文件。
v = videowriter('peaks.avi');打开(v);
生成初始数据,设置轴和图形属性。
Z = peaks; surf(Z); axis紧的manualset(GCA,'nextplot','replacechildren');
Create a set of frames and write each frame to the file.
fork = 1:20冲浪(sin(2*pi*k/20)*z,z)帧= getFrame(gcf);writeVideo(v,框架);end关闭(v);
See Also
Topics
Introduced in R2010b
matlab命令
You clicked a link that corresponds to this MATLAB command:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。金宝app
Select a Web Site
选择一个网站以获取可用的翻译内容,并查看本地事件和优惠。根据您的位置,我们建议您选择:。
You can also select a web site from the following list:
如何获得最佳网站性能
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(英语)
- United States(英语)