vision.VideoFileWriter System object

Package: vision

Write video frames and audio samples to video file

Description

The VideoFileWriter object writes video frames and audio samples to a video file. .mwv files can be written only on Windows®. The video and audio can be compressed. The available compression types depend on the encoders installed on the platform.

    Note   This block supports code generation for platforms that have file I/O available. You cannot use this block with Real-Time Windows Target™ software, because that product does not support file I/O.

    This object performs best on platforms with Version 11 or later of Windows Media® Player software. This object supports only uncompressed RGB24 AVI files on Linux® and Mac platforms.

    Windows 7 UAC (User Account Control), may require administrative privileges to encode .mwv and .wma files.

The generated code for this object relies on prebuilt library files. You can run this code outside the MATLAB® environment, or redeploy it, but be sure to account for these extra library files when doing so. The packNGo function creates a single zip file containing all of the pieces required to run or rebuild this code. See packNGo for more information.

To run an executable file that was generated from an object, you may need to add precompiled shared library files to your system path. See MATLAB Coder and Simulink Shared Library Dependencies for details.

This object allows you to write .wma/.wmv streams to disk or across a network connection. Similarly, the vision.VideoFileReader object allows you to read .wma/.wmv streams to disk or across a network connection. If you want to play an .mp3/.mp4 file, but you do not have the codecs, you can re-encode the file as .wma/.wmv, which is supported by the Computer Vision System Toolbox™.

Construction

videoFWriter = vision.VideoFileWriter returns a video file writer System object, videoFWriter. It writes video frames to an uncompressed 'output.avi' video file. Every call to the step method writes a video frame.

videoFWriter = vision.VideoFileWriter(FILENAME) returns a video file writer object, videoFWriter that writes video to a file, FILENAME. The file type can be .avi or .wmv, specified by the FileFormat property.

videoFWriter = vision.VideoFileWriter(...,'Name',Value) configures the video file writer properties, specified as one or more name-value pair arguments. Unspecified properties have default values.

Code Generation Support
Supports MATLAB Function block: Yes
System Objects in MATLAB Code Generation
Generated code for this function uses a precompiled platform-specific shared library.
Code Generation Support, Usage Notes, and Limitations.

To write to a file:

  1. Define and set up your video file writer object using the constructor.

  2. Call the step method with the optional output filename, FILENAME, the video file writer object, videoFWriter, and any optional properties. See the syntax below for using the step method.

step(videoFWriter,I) writes one frame of video, I, to the output file. The input video can be an M-by-N-by-3 truecolor RGB video frame, or an M-by-N grayscale video frame.

step(videoFWriter,Y,Cb,Cr) writes one frame of YCbCr 4:2:2 video. The width of Cb and Cr color components must be half of the width of Y. You must set the value of the FileColorSpace property to 'YCbCr 4:2:2'.

step(videoFWriter,I,AUDIO) writes one frame of the input video, I, and one frame of audio samples, AUDIO, to the output file. This applies when you set the AudioInputPort property to true.

step(videoFWriter,Y,Cb,Cr,AUDIO) writes one frame of YCbCr 4:2:2 video, and one frame of audio samples, AUDIO, to the output file. This applies when you set the AudioInputPort to true and the FileColorSpace property to 'YCbCr 4:2:2'. The width of Cb and Cr color components must be half of the width of Y.

Properties

Filename

Video output file name

Specify the name of the video file as a string.

Default: output.avi

FileFormat

Output file format

Specify the format of the file that is created. Supported formats and abbreviations:

.wmv

Windows Media Video

Windows

.avi

AVI Audio-Video Interleave file

All platforms

.mj2

Motion JPEG 2000 file

All platforms

.MPEG4

MPEG-4 file

(systems with Windows 7 or later, or Mac OS X 10.7 and later)

Default: .avi

AudioInputPort

Write audio data

Use this property to control whether the object writes audio samples to the video file. Set this value to true to write audio data.

Default: false

FrameRate

Video frame rate

Specify the frame rate of the video data in frames per second as a positive numeric scalar.

For videos which also contain audio data, the rate of the audio data will be determined as the rate of the video multiplied by the number of audio samples passed in each invocation of the step method. For example, if you use a frame rate of 30, and pass 1470 audio samples to the step method, the object sets the audio sample to 44100, (1470×30=44100).

Default: 30

AudioCompressor

Audio compression encoder

Specify the type of compression algorithm to implement for audio data. This compression reduces the size of the video file. Choose None (uncompressed) to save uncompressed audio data to the video file. The other options reflect the available audio compression algorithms installed on your system. This property applies only when writing AVI files on Windows platforms.

VideoCompressor

Video compression encoder

Specify the type of compression algorithm to use to compress the video data. This compression reduces the size of the video file. Choose None (uncompressed) to save uncompressed video data to the video file. The VideoCompressor property can also be set to one of the compressors available on your system. To obtain a list of available video compressors, you can use tab completion. Follow these steps:

  1. Instantiate the object:

    y = vision.VideoFileWriter
  2. To launch the tab completion functionality, type the following up to the open quote.

    y.VideoCompressor='

    A list of compressors available on your system will appear after you press the Tab key. For example:

This property applies only when writing AVI files on Windows platforms.

AudioDataType

Uncompressed audio data type

Specify the compressed output audio data type. This property only applies when you write uncompressed WAV files.

FileColorSpace

Color space for output file

Specify the color space of AVI files as RGB or YCbCr 4:2:2. This property applies when you set the FileFormat property to AVI and only on Windows platforms.

Default: RGB

Methods

Examples

expand all

Write a Video to an AVI File

Set up the reader and writer objects.

videoFReader = vision.VideoFileReader('viplanedeparture.avi');
videoFWriter = vision.VideoFileWriter('myFile.avi','FrameRate',videoFReader.info.VideoFrameRate);

Write the first 50 frames from original file into a newly created AVI file.

for i=1:50
    videoFrame = step(videoFReader);
    step(videoFWriter, videoFrame);
end

Close the input and output files.

release(videoFReader);
release(videoFWriter);
Was this topic helpful?