Export QuickTime Movies with Matlab
OBJ = QTWriter(FILENAME)
constructs a QTWriter object to write QuickTime movie data to a .mov file using lossless Photo PNG compression. FILENAME
is a string enclosed in single quotation marks that specifies the name of the file to create. If FILENAME
does not include an extension the QTWriter constructor appends the .mov extension. FILENAME
can include an absolute or relative path.
OBJ = QTWriter(...,'PropertyName','PropertyValue',...)
specifies options via property name-value pairs. In addition to the default 'Photo PNG'
compression, 'Photo TIFF'
and 'Photo JPEG'
formats can be specified via the 'MovieFormat'
property. Lossless Photo TIFF compression yields larger file sizes than Photo PNG, but is faster (using 'LZW'
or the default 'PackBits'
for the 'CompressionType'
property). Photo JPEG is a lossy format and the 'Quality'
property can be used to specify the level of compression to use. The 'ColorSpace'
property specifies if the movie is to be output as 24-bit RGB truecolor or 8-bit grayscale. The 'Transparency'
property indicates if the movie is to be output with an alpha channel (Photo PNG format only).
Frames are written via the writeMovie(FRAME)
method of the QTWriter object. The frame rate of the movie can be continuously varied via the 'FrameRate'
property of the QTWriter object (see strpenddemo
). The looping behavior of the output movie can be specified via the 'Loop'
property of the QTWriter object: 'none'
, 'loop'
, or 'backandforth'
. Finally, the output movie can be forced to play every frame via the 'PlayAllFrames'
property of the QTWriter object. The close()
method of the QTWriter object is called to finish writing the movie and clean up associated data.
Please refer to the detailed help included within QTWriter
for further details and options.
% Prepare new movie file using the default PNG compression
movObj = QTWriter('peaks.mov');
% Create an animation
hf = figure; Z = peaks; surfc(Z); frames = 100;
axis tight; set(hf,'DoubleBuffer','on');
set(gca,'nextplot','replacechildren');
% Animate plot and write movie
for k = 0:frames
hs = surfc(sin(2*pi*k/frames)*Z,Z);
set(hs,'FaceColor','interp','FaceLighting','phong');
light('Position',[0 0 4]);
% Vary the frame-rate
movObj.FrameRate = k;
% Write each frame to the file
writeMovie(movObj,getframe(hf));
end
% Set palindromic looping flag
movObj.Loop = 'backandforth';
% Finish writing movie and close file
close(movObj);
Example output: