QTWriter

Export QuickTime Movies with Matlab

Version 1.1, 12-3-13

View the Project on GitHub horchler/QTWriter

QTWriter

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.

Example:

% 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:

(Download Movie, 5.1 MB QuickTime)

The included demo, strpenddemo, provides a more-detailed usage example. The M-file simulates and animates a string pendulum hanging between two cylinders and generates this variable frame-rate movie using QTWriter:


(Download Movie, 1.5 MB QuickTime)


Also included is getframebg, a faster version of Matlab's getframe. It captures figures in the background without rendering content to the screen, making it faster, avoiding capture of overlapping windows, and allowing the use of screensavers.



Copyright © Andrew D. Horchler, adh9 @ case . edu
Created: 10-3-11, Revision: 1.1, 12-3-13

QTWriter is inspired by MakeQTMovie by Malcolm Slaney (Interval Research, March 1999) and parts are based on the VideoWriter class in Matlab R2011b.

This version tested with Matlab 8.1.0.604 (R2013a)
Mac OS X 10.9 Build: 13A603, Java 1.6.0_65-b14-462-11M4609
QuickTime Player Pro 7.6.6 (1709), QuickTime Version 7.7.3 (2826), and QuickTime Player X 10.3 (727.1)
Compatibility maintained back through Matlab 7.4 (R2007a)

Copyright © 2012–2013, Andrew D. Horchler
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANDREW D. HORCHLER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.