| Contents | Index |
Write video files
Use the VideoWriter function with the open, writeVideo, and close methods to create video files from figures, still images, or MATLAB movies. VideoWriter can create AVI and Motion JPEG 2000 files on all platforms, and MPEG-4 files on Windows 7 platforms. VideoWriter supports files larger than 2 GB, which is the limit for avifile.
To set video properties, VideoWriter includes predefined profiles such as 'Uncompressed AVI' or 'MPEG-4'.
writerObj = VideoWriter(filename) constructs a VideoWriter object to write video data to a compressed AVI file.
writerObj = VideoWriter(filename,profile) applies a set of properties tailored to a specific file format (such as 'MPEG-4' or 'Uncompressed AVI') to a VideoWriter object.
profile |
String enclosed in single quotation marks that describes the type of file to create. Specifying a profile sets default values for video properties such as VideoCompressionMethod. Possible values:
Default: 'Motion JPEG AVI' |
ColorChannels |
Number of color channels in each output video frame. (Read-only) AVI and MPEG-4 files have three color channels (RGB). The number of channels for Motion JPEG 2000 files depends on the input data to the writeVideo method: one for monochrome image data, three for color data. | ||||||||||||||||||
CompressionRatio |
Number greater than 1 that specifies the target ratio between the number of bytes in the input image and the number of bytes in the compressed image. The data is compressed as much as possible, up to the specified target. Only available for objects associated with Motion JPEG 2000 files. After you call open, you cannot change the CompressionRatio value. If you previously set LosslessCompression to true, setting CompressionRatio generates an error. Default: 10 | ||||||||||||||||||
Duration |
Scalar value specifying the duration of the file in seconds. (Read-only) | ||||||||||||||||||
FileFormat |
String specifying the type of file to write: 'avi', 'mp4', or 'mj2'. (Read-only) | ||||||||||||||||||
Filename |
String specifying the name of the file. (Read-only) | ||||||||||||||||||
FrameCount |
Number of frames written to the video file. (Read-only) | ||||||||||||||||||
FrameRate |
Rate of playback for the video in frames per second. After you call open, you cannot change the FrameRate value. Default: 30 | ||||||||||||||||||
Height |
Height of each video frame in pixels. The writeVideo method sets values for Height and Width based on the dimensions of the first frame. (Read-only) 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, VideoWriter pads the frame with a row of black pixels at the bottom. | ||||||||||||||||||
LosslessCompression |
Boolean value (logical true or false) only available for objects associated with Motion JPEG 2000 files. If true:
After you call open, you cannot change the LosslessCompression value. Default: false for the 'Motion JPEG 2000' profile, true for the 'Archival' profile | ||||||||||||||||||
MJ2BitDepth |
Number of least significant bits in the input image data, from 1 to 16. Only available for objects associated with Motion JPEG 2000 files. If you do not specify a value before calling the open method, 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, MJ2BitDepth is 8. | ||||||||||||||||||
Path |
String specifying the fully qualified path. (Read-only) | ||||||||||||||||||
Quality |
Number from 0 through 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. Only available for objects associated with the MPEG-4 or Motion JPEG AVI profile. After you call open, you cannot change the Quality value. Default: 75 | ||||||||||||||||||
VideoBitsPerPixel |
Number of bits per pixel in each output video frame. (Read-only) AVI and MPEG-4 files have 24 bits per pixel (8 bits for each of three color bands). 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, the default value of MJ2BitDepth is 16, and VideoBitsPerPixel is 48 (three times the bit depth). | ||||||||||||||||||
VideoCompressionMethod |
String indicating the type of video compression: 'None', 'H.264', 'Motion JPEG', or 'Motion JPEG 2000'. (Read-only) | ||||||||||||||||||
VideoFormat |
String indicating the MATLAB representation of the video format. (Read-only) For AVI or MPEG-4 files, VideoFormat is 'RGB24'. For Motion JPEG 2000 files, VideoFormat depends 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, VideoWriter sets the format as shown in this table.
| ||||||||||||||||||
Width |
Width of each video frame in pixels. The writeVideo method sets values for Height and Width based on the dimensions of the first frame. (Read-only) 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, VideoWriter pads the frame with a column of black pixels along the right side. |
| close | Close file after writing video data |
| getProfiles | List profiles and file formats supported by VideoWriter |
| open | Open file for writing video data |
| writeVideo | Write video data to file |
Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB Programming Fundamentals documentation.
Construct a VideoWriter object and view its properties.
writerObj = VideoWriter('newfile.avi')Set the frame rate to 60 frames per second.
writerObj.FrameRate = 60;
Write a sequence of frames to a compressed AVI file, peaks.avi.
Prepare the new file.
writerObj = VideoWriter('peaks.avi');
open(writerObj);Generate initial data and set axes and figure properties.
Z = peaks; surf(Z); axis tight set(gca,'nextplot','replacechildren'); set(gcf,'Renderer','zbuffer');
Setting the Renderer property to zbuffer or Painters works around limitations of getframe with the OpenGL renderer on some Windows systems.
Create a set of frames and write each frame to the file.
for k = 1:20 surf(sin(2*pi*k/20)*Z,Z) frame = getframe; writeVideo(writerObj,frame); end close(writerObj);

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |