How to | Import and Export Animations

After creating or editing an animation in Mathematica, you can export it for use in other programs. Mathematica can import and export animations in several formats.

Selected examples from the video:

View the elements available for Import in a QuickTime file in the Mathematica documentation ExampleData directory:

In[1]:=
Click for copyable input
Out[1]=

Import the QuickTime file as an animation:

In[2]:=
Click for copyable input
Out[2]=

Use Length to see how many frames are in the animation:

In[38]:=
Click for copyable input
Out[38]=

Import a specific frame of the animation:

In[35]:=
Click for copyable input
Out[35]=

Use to import all of the frames in a list. You can do the same thing by using in place of :

In[7]:=
Click for copyable input

Use ImageResize with Scaled to make each frame half its original size:

In[27]:=
Click for copyable input

Use Sharpen on each of the frames:

In[28]:=
Click for copyable input

Use ListAnimate to make a new animation from the processed frames:

In[29]:=
Click for copyable input
Out[29]=

Export the new animation to SWF, which is a format based on Flash. The symbol specifies the most recent output, which in this case is the animation:

In[11]:=
Click for copyable input
Out[11]=

If you open the exported animation, you will see that it contains non-functional controls across the top. The animation is essentially a movie of a movie. To exclude these controls from the exported animation, simply export the list of frames directly to a file format supported by animations.

Here, the list of frames (stored in the symbol ) is exported directly to SWF:

In[12]:=
Click for copyable input
Out[12]=
    

You can also import and export animations that you create in Mathematica.

First, use Table to create 5 plots of where :

In[3]:=
Click for copyable input
Out[3]=

Use ListAnimate to create an animation from the list of plots:

In[4]:=
Click for copyable input
Out[4]=

As before, exporting the list of frames (in this case the plots) directly to a file format supported for use in animations creates an animation of the frames:

In[29]:=
Click for copyable input
Out[29]=

Once an animation is exported, you can also import it back into Mathematica:

In[30]:=
Click for copyable input
Out[30]=
    

You can also export Manipulate objects as animations.

Use Manipulate with Plot3D to create an interactive 3D plot of where the value of varies from 0 to 4:

In[66]:=
Click for copyable input
Out[66]=

The next three steps are equivalent ways to export the entire Manipulate object, controls and all, to an animation.

Here the most recent output, which is the Manipulate object, is exported:

In[67]:=
Click for copyable input
Out[67]=

The Manipulate is also stored to , so exporting produces the same result:

In[68]:=
Click for copyable input
Out[68]=

You can also put the Manipulate expression inside the Export expression:

In[69]:=
Click for copyable input
Out[69]=

The animations , , and are identical. They also contain the framing and controls typical of Manipulate objects in Mathematica.

To export animations that lack the framing or controls, you should generate a list of graphics representing a suitable number of steps used in the Manipulate and then export that list to a file format used for animations.

For example, use Table to create a list plot of and specify that should move from 0 to 4 in steps of 0.2:

In[70]:=
Click for copyable input

Export the list of graphics to the file :

In[71]:=
Click for copyable input
Out[71]=

You can create a longer, smoother animation by reducing the step size used in Table. For instance, reducing the step size from 0.2 to 0.1 will result in twice the number of plots in the list and subsequently, twice the number of frames when it is exported as an animation.

Correspondingly, the file size of the animation, as well as the time it takes Mathematica to create both the plots and animation, will approximately double.

New to Mathematica? Find your learning path »
Have a question? Ask support »