Write video frames and audio samples to video file
The VideoFileWriter object writes video frames and audio samples to a video file. It can write video and/or audio to an AVI or WMV file. WMV 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 WMV 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.
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™.
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.
Define and set up your video file writer object using the constructor.
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.
Video output file name
Specify the name of the video file as a string.
Output file format
Specify the format of the file that is created. On Windows platforms, this may be AVI or WMV. On other platforms, this value is restricted to AVI. These abbreviations correspond to the following file formats:
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.
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, ( ).
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.
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:
This property applies only when writing AVI files on Windows platforms.
Uncompressed audio data type
Specify the compressed output audio data type. This property only applies when you write uncompressed WAV files.
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.
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 of the viplanedeparture.avi file into a newly created file, myFile.avi.
for i=1:50 videoFrame = step(videoFReader); step(videoFWriter, videoFrame); end
Close the input and output files.