Documentation

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.

创建

CreateVideoWriterobjects using theVideoWriterfunction.

特性

展开全部

此属性仅阅读。

每个输出视频框架中的颜色通道数,指定为一个正整数:

  • 未压缩的AVI,Motion JPEG AVI和MPEG-4文件具有三个颜色通道。

  • Indexed and grayscale AVI files have one color channel.

  • 对于Motion JPEG 2000文件,频道的数量取决于输入数据写入功能:单色图像数据之一,三个用于颜色数据。

数据类型:双倍的

视频文件的颜色信息,指定为具有三列和最多256行的数字矩阵。矩阵中的每一行都使用RGB三重态定义一种颜色。RGB三重态是一个三元素行矢量,其元素指定了颜色的红色,绿色和蓝色组件的强度。强度必须在范围内[0,1]

You can set the colormap explicitly before the call to打开,或使用colormapfield of a movie frame structure at the time of writing the first frame.

Colormapproperty only applies to objects used for writing indexed AVI files.

例子:colormap(summer(256))

数据类型:双倍的|UINT8

目标压缩比,指定为大于1的整数。压缩比是输入图像中的字节数与压缩图像中的字节数之间的比率。视频数据尽可能被压缩到指定目标。

CompressionRatio仅适用于编写运动JPEG 2000文件的对象。后你叫打开,你不能更改CompressionRatio价值。If you previously setLosslessCompressiontrue, settingCompressionRatiogenerates an error.

例子:5

数据类型:单身的|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64

此属性仅阅读。

Duration of the output file in seconds, specified as a scalar value.

数据类型:双倍的

此属性仅阅读。

要编写的文件类型,指定为'avi','mp4', 或者'MJ2'

此属性仅阅读。

Name of file, specified as a character vector.

数据类型:char

此属性仅阅读。

帧数written to the video file, specified as an integer.

数据类型:双倍的

视频播放速度in frames per second, specified as a positive number.

后你叫打开,你不能更改FrameRate价值。

例子:10

数据类型:单身的|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64

此属性仅阅读。

每个视频框架的高度在像素中,指定为标量。这写入method sets values forHeightandWidth基于第一帧的尺寸。

MPEG-4文件需要框架尺寸,这些尺寸可除以两个。如果MPEG-4文件的输入帧高度不是偶数号码,则VideoWriterpads the frame with a row of black pixels at the bottom. For MPEG-4 files on Windows®系统,允许的值取决于Windows的版本。例如,在Windows 10上允许Heightis in the range[34,2160]

数据类型:双倍的

Lossless compression, specified astrueorfalse。这LosslessCompression属性仅适用于编写运动JPEG 2000文件的对象。

IfLosslessCompressionistrue,那么:

  • 写入函数写入数据,使解压缩数据与输入数据相同。

  • VideoWriter忽略任何指定的值CompressionRatio

后你叫打开,你不能更改LosslessCompression价值。

默认情况下,LosslessCompressionisfalsefor the“运动JPEG 2000”profile andtruefor the'Archival'概要文件。

数据类型:logical

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文件的对象。如果您在调用该值之前不指定值打开方法,VideoWritersets the bit depth based on the input data type. For example, if the input data to写入is an array ofUINT8orint8values, thenMJ2BitDepthis8

例子:8

数据类型:单身的|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64

此属性仅阅读。

视频文件的完整路径,指定为字符向量。

数据类型:char

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-4orMotion JPEG AVI概要文件。后你叫打开,你不能更改质量价值。

例子:50

数据类型:单身的|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64

此属性仅阅读。

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 ofMJ2BitDepthand the number of bands of image data. For example, if the input data to写入is a three-dimensional array ofUINT16orINT16values, the default value ofMJ2BitDepthis16, andVideoBitsperpixelis48(three times the bit depth).

数据类型:双倍的

此属性仅阅读。

视频压缩类型,指定为'没有任何','H.264',“运动jpeg', 或者“运动JPEG 2000”

数据类型:char

此属性仅阅读。

视频格式的MATLAB表示,指定为字符向量。

For file types other than Motion JPEG 2000 files,videoformat是以下内容之一。

视频格式

Value ofvideoformat

未压缩的AVI,运动JPEG AVI或MPEG-4文件

'RGB24'

AVI files with indexed video

'索引'

带有灰度视频的AVI文件

“灰度”

For Motion JPEG 2000 files,videoformat取决于价值MJ2BitDepthand the format of the input image data to the写入method. For example, if you do not specify theMJ2BitDepthproperty,VideoWritersets the format as shown in this table.

Format of Image Data

Value ofvideoformat

Single-bandUINT8 'Mono8'
Single-bandint8 'Mono8 Signed'
Single-bandUINT16 'mono16'
Single-bandINT16 'Mono16 Signed'
三个伴侣UINT8 'RGB24'
三个伴侣int8 'RGB24 Signed'
三个伴侣UINT16 'RGB48'
三个伴侣INT16 'RGB48 Signed'

此属性仅阅读。

每个视频框架的宽度以像素为单位,指定为数字标量。这写入function sets values forHeightandWidth基于第一帧的尺寸。

MPEG-4文件需要框架尺寸,这些尺寸可除以两个。If the input frame width for an MPEG-4 file is not an even number, thenVideoWriter沿右侧用黑色像素列将框架垫板。对于Windows系统上的MPEG-4文件,允许的值取决于Windows的版本。例如,在Windows 10上允许Widthis 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

例子

展开全部

Create aVideoWriterobject 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)

Create an array containing data from the sample still image,peppers.png

a = imread('peppers.png');

Create aVideoWriterobject 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)

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

Introduced in R2010b

Was this topic helpful?