Programming Previous page   Next Page

Exporting Audio/Video Data

MATLAB includes several functions that you can use to export audio or video data from the MATLAB workspace. These functions write audio data to a file using specific file formats. The following sections describe

This section also provides an example of writing video data to a file in Example: Creating an AVI file.

Exporting Audio Data

In MATLAB, audio data is simply numeric data that you can export using standard MATLAB data export functions, such as save.

MATLAB also includes several functions that write audio data to files in specific file formats:

Exporting Video Data in AVI Format

You can export MATLAB video data as an Audio/Video Interleaved (AVI) file. To do this, you use the avifile function to create an avifile object. Once you have the object, you can use AVI file object methods and properties to control various aspects of the data export process.

For example, in MATLAB, you can save a sequence of graphs as a movie that can then be played back using the movie function. You can export a MATLAB movie by saving it in MAT-file format, like any other MATLAB workspace variable. However, anyone who wants to view your movie must have MATLAB. (For more information about MATLAB movies, see the Animation section in the MATLAB Graphics documentation.)

To export a sequence of MATLAB graphs in a format that does not require MATLAB for viewing, save the figures in Audio/Video Interleaved (AVI) format. AVI is a file format that allows animation and video clips to be played on a PC running Windows or on UNIX systems.

Example: Creating an AVI file

To export a sequence of MATLAB graphs as an AVI format movie, perform these steps:

  1. Create an AVI file object, using the avifile function.
  1. AVI file objects support properties that let you control various characteristics of the AVI movie, such as colormap, compression, and quality. (See the avifile reference page for a complete list.) avifile uses default values for all properties, unless you specify a value. The example sets the value of the frames per second (fps) property.

  1. Capture the sequence of graphs and put them into the AVI file, using the addframe function.
  1. The example uses a for loop to capture the series of graphs to be included in the movie. You typically use addframe to capture a sequence of graphs for AVI movies. However, because this particular MATLAB animation uses XOR graphics, you must call getframe to capture the graphs and then call addframe to add the captured frame to the movie.

  1. Close the AVI file, using the close function.

Previous page  Importing Audio/Video Data Working with Spreadsheets Next page

© 1994-2005 The MathWorks, Inc.