VideoWriter

Description

Use a VideoWriter object to create a video file from an
array or MATLAB® movie. The object contains information about the video and the properties
that control the output video. You can create a VideoWriter object
using the VideoWriter function, specify its properties, and then write the video using object functions.

If you do not specify a valid file extension,
VideoWriter appends the extension
.avi, .mj2, or
.mp4, depending on the value of the
profile argument. If you do not specify a value
for profile, then VideoWriter
creates a Motion JPEG compressed AVI file with the extension
.avi.

Properties

The VideoWriter object contains properties that control the
output video. You can create a VideoWriter object with properties
tailored to a specific format, such as 'Uncompressed AVI' or
'MPEG-4', by using the VideoWriter function
with a predefined profile. For example, you can create a
VideoWriter object with a Motion JPEG AVI
profile and assign a value to the Quality property.

v = VideoWriter('newfile.avi','Motion JPEG AVI');
v.Quality = 95;

After you call the open function on the
VideoWriter object, you cannot change the value of a property.
Therefore, modify property values before opening the video file for writing.

ColorChannels — Number of color channelspositive integer

This property is read-only.

Number of color channels in each output video frame, specified as a
positive integer:

For Motion JPEG 2000 files, the number of channels depends on the
input data to the writeVideo function: one for
monochrome data or three for color data.

Data Types: double

Colormap — Color information for video fileP-by-3 numeric matrix

Color information for video file, specified as a numeric matrix with three
columns and a maximum of 256 rows. Each row in the matrix defines one color
using an RGB triplet. An RGB triplet is a three-element row vector whose
elements specify the intensities of the red, green, and blue components of
the color. The intensities must be in the range
[0,1].

You can set the colormap explicitly before the call to
open, or by using the colormap
field of a movie frame structure at the time of writing the first
frame.

The Colormap property only applies to objects used for
writing indexed AVI files.

Target compression ratio, specified as an integer greater than 1. The
compression ratio is the ratio between the number of bytes in the input
image and the number of bytes in the compressed image. The video data is
compressed as much as possible, up to the specified target.

CompressionRatio is available only for objects used for
writing Motion JPEG 2000 files. After you call open, you
cannot change the CompressionRatio value. If you
previously set LosslessCompression to
true, then setting
CompressionRatio generates an error.

Height — Height of each video framescalar

This property is read-only.

Height of each video frame in pixels, specified as a scalar. The
writeVideo method sets values for
Height and Width based on the
dimensions of the first frame.

MPEG-4 files require frame dimensions that are divisible by two. If the
input frame height for an MPEG-4 file is not an even number, then
VideoWriter pads the frame with a row of black pixels
at the bottom. For MPEG-4 files on Windows systems, the allowed value depends on the version of
Windows. For example, on Windows 10 the allowed Height is in the range
[34,2160].

Data Types: double

LosslessCompression — Lossless compressiontrue | false

Lossless compression, specified as true or
false. The LosslessCompression
property is only available for objects used for writing Motion JPEG 2000
files.

If LosslessCompression is true,
then:

The writeVideo function writes data so that
the decompressed data is identical to the input data.

VideoWriter ignores any specified value for
CompressionRatio.

After you call open, you cannot change the
LosslessCompression value.

By default, LosslessCompression is
false for the 'Motion JPEG 2000'
profile and true for the 'Archival'
profile.

Bit depth for Motion JPEG 2000 files, specified as an integer in the range
[1,16]. The bit depth is the number of
least-significant bits in the input image data

MJ2BitDepth is available only for objects used for
writing Motion JPEG 2000 files. If you do not specify a value before calling
the open method, then VideoWriter sets
the bit depth based on the input data type. For example, if the input data
to writeVideo is an array of uint8 or
int8 values, then MJ2BitDepth is
8.

VideoBitsPerPixel — Number of bits per pixelnumeric 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).

Indexed and grayscale AVI files have 8 bits per pixel.

For Motion JPEG 2000 files, the number of bits per pixel depends on the
value of MJ2BitDepth and the number of bands of image
data. For example, if the input data to writeVideo is a
three-dimensional array of uint16 or
int16 values, then the default value of
MJ2BitDepth is 16, and
VideoBitsPerPixel is 48 (three
times the bit depth).

VideoFormat — MATLAB representation of video formatcharacter vector

MATLAB representation of the video format, specified as a character
vector.

For file types other than Motion JPEG 2000 files,
VideoWriter sets VideoFormat to
one of the following.

Video Format

Value of VideoFormat

Uncompressed AVI, Motion JPEG AVI, or MPEG-4
files

'RGB24'

AVI files with indexed video

'Indexed'

AVI files with grayscale video

'Grayscale'

For Motion JPEG 2000 files, VideoWriter sets the
VideoFormat based on the value of
MJ2BitDepth and the format of the input image data to
the writeVideo method. For example, if you do not specify
the MJ2BitDepth property, then
VideoWriter sets the format as shown here.

Format of Image Data

Value of VideoFormat

Single-band uint8

'Mono8'

Single-band int8

'Mono8 Signed'

Single-band uint16

'Mono16'

Single-band int16

'Mono16 Signed'

Three-banded uint8

'RGB24'

Three-banded int8

'RGB24 Signed'

Three-banded uint16

'RGB48'

Three-banded int16

'RGB48 Signed'

Width — Width of each video framenumeric scalar

This property is read-only.

Width of each video frame in pixels, specified as a numeric scalar. The
writeVideo function sets values for
Height and Width based on the
dimensions of the first frame.

MPEG-4 files require frame dimensions that are divisible by two. If the
input frame width for an MPEG-4 file is not an even number, then
VideoWriter pads the frame with a column of black
pixels along the right side. For MPEG-4 files on Windows systems, the allowed value depends on the version of
Windows. For example, on Windows 10 the allowed Width is in the range
[34,3872].