Generating PDF With Animations Using LaTeX
Generating PDF With Animations Using LaTeX
Generating PDF With Animations Using LaTeX
html
The context of this page is the problem of how to prepare scientific/technical documents. If
you have looked at my suggestions for doing scientific presentations using Apple's Keynote,
you should be convinced by now that LaTeX is an essential ingredient for any computer-based
talk with mathematical content.
In particular, I included some links to LaTeX-based PDF presentation tools that can do almost
anything that Keynote can do, based on the power of Adobe Reader.
For all of these cases, LaTeX provides solutions. The first two are addressed by the movie15
package and its successor, media9. The last solution can be achievd by the animate package.
We'll not discuss the latter on this page.
Prerequisites
PDF movies can be displayed with Adobe Reader. In case you encounter problems, first make
sure you have the most recent version of Adobe Reader. The Preview Application (on Mac)
is not an alternative here because it does not handle multimedia plugins and JavaScript.
For Linux users running the latest version of Adobe Reader, the embedded movie will open in
a separate window after you click on the "paper clip" attachment icon and agree to open the
file.
Also note that you cannot use Linux acroread to display multimedia embedded with the help
of this package. In KDE 4, you may be able to use Okular to view PDFs with embedded
movies (unfortunately I can't currently test these features on Linux or Windows, only on Mac).
One more warning: we are using advanced features of PDF here, so you also need a recent
version (>1.2) of pdflatex. The TeX-Live 2007 (and later) distribution contains movie15,
whereas the tetex distribution doesn't. That's why you should no longer be using texlive.
1 of 6 9/25/2016 12:15 AM
Generating PDF with animations using LaTeX http://pages.uoregon.edu/noeckel/PDFmovie.html
To create MPEG or other formats, here are some tools (for Mac OS X):
GraphicConverter can convert a sequence of images into a movie using File > Export
Slide Show to Movie
Miro Video Converter has many of the most common export file settings pre-defined. I
found its Apple Universal mp4 output format works well when embedded in PDF (also
works with media9 below).
Livid Batch Export Utility lets you convert movies from one format to another, while also
changing the compression and size settings.
QT amateur is a free movie player for Mac OS X which can export various movie and
image file formats (even in batch mode). It requires Quicktime 7 to be installed on your
machine.
Apple's Quicktime X application lets you comvert to different formats under the Share
and FIle > Export...
menu items. In particular, exporting to 480p produced .mov files that work with media9,
see below.
If you are comfortable with command-line UNIX tools, there are the free packages
mpeg2vidcodec or mpegencode, available for Mac from fink or MacPorts. The
Imagemagick package also has the command convert which on my platform allows
conversion to mpgeg (by automatically calling one of the programs mentioned before)..
Flash movies work, too, and this opens additional possibilities for interactivity in your PDF
document. Flash animations can be exported from Mathematica, among others.
This last point is where the newer media9 package differs from movie15: it relies on the fact
that recent versions of Adobe Reader have Flash Player built in, so that external players don't
need to be installed if you deliver the embedded movie wrapped in a flash "container." Of
course, most computers nowadays do have players for a multitude of movie formats installed
anyway; that's why I think it's still worth discussing movie15 first.
The examples here are best suited for a small, "bare-bones" presentation without much
stylistic overhead. For the media9 approach, scroll down.
For several years, the way I've been putting movies into PDF presentations has been based on
direct application of \pdfannot or \pdfmark - commands understood by pdflatex which allow
you to write PDF code. The style movie15.sty by Alexander Grahn uses these commands to
create a very flexible and user-friendly way to do this without having to leave the LaTeX level.
This package is able to use the features of the newest Adobe Reader, including 3D virtual
reality interactivity. Here, I'll address only traditional movie playback to keep things simple.
2 of 6 9/25/2016 12:15 AM
Generating PDF with animations using LaTeX http://pages.uoregon.edu/noeckel/PDFmovie.html
1. Assume you have the following movie in MPEG or AVI format (I have an mp4 movie on this
web page, but other formats also work):
\documentclass[12pt,landscape]{article}
\usepackage{geometry}
\geometry{verbose,letterpaper}
\usepackage{movie15}
\usepackage{hyperref}
\begin{document}
Whispering-gallery mode in a quarter circle:
\begin{figure}[ht]
\includemovie[
poster,
text={\small(Loading Circle-m-increase3.mp4)}
]{6cm}{6cm}{Circle-m-increase3.mp4}
\end{figure}
\end{document}
3 of 6 9/25/2016 12:15 AM
Generating PDF with animations using LaTeX http://pages.uoregon.edu/noeckel/PDFmovie.html
Adobe Reader or Acrobat. The output file can also be downloaded by clicking here.
The movie is automatically loaded and represented by its first frame ("poster frame").
Playback starts after you click on the picture and stops on the last frame. I didn't put in
any visible movie controls because they appear to be buggy under Windows (thanks to
Alexander Grahn for mentioning this). With Mac OS X, controls work fine, so you could
add the option controls to \includemovie and obtain the same appearance as on this
web page. Even without control buttons, one can always restart the movie by double-
clicking on it (this applies to Mac; for Windows, you may just need a single click).
This dependence on external video players is removed by the media9 package below.
Vector animations
Everything that was said above also applies if the movie you want to include is in Flash SWF
format. As mentioned above, the big advantage is that Flash delivers vector animation inside
your PDF document. An example file, movie-swf.pdf, shows the result of modifying the
\includemovie line in our tex file as follows:
\documentclass[12pt,landscape]{article}
\usepackage{geometry}
\geometry{verbose,letterpaper}
\usepackage{movie15}
\usepackage{hyperref}
\begin{document}
Created by James N{\"o}ckel, January 6, 2008:
\begin{figure}[h!]
\includemovie[
poster=FlashPoster.jpg,
text={\Large\bf Click to start\hspace*{400pt}}
]{550pt}{400pt}{blendone.swf}
\end{figure}
\end{document}
This works on OS X provided you have installed the latest update of Adobe Reader
(with version 9.1 installed, Adobe Updater provides a fixed version 9.1.2).
Since the poster frame (image shown before the movie is started) can't be found automatically
for this Flash animation, I've inserted an image FlashPoster.jpg by hand. As above, you need
Adobe Reader to play this movie. Version 8 is required, as is an up-to-date version of Flash
Player. The animation blendone.swf was created by James Nckel, Jan. 06, 2008. Please credit
him if you distribute this file in any way!
Speaking of credit for authors of digital media: Adobe has recently announced enhanced
digital-rights management capabilities for Flash. Other formats such as Quicktime already offer
this, so there isn't really any surprise that Flash wants to offer it, too. The worry may be that
Flash movies and games will therefore become less freely available. Looking at some of the
4 of 6 9/25/2016 12:15 AM
Generating PDF with animations using LaTeX http://pages.uoregon.edu/noeckel/PDFmovie.html
Flash games that are out there, this may actually be a good thing... (take this page for
example).
But the truth is that giving the author some control over what people do with his or her work
should generally be a matter of common sense. It is not in itself a bad development, because
authors who want to distribute their work for free can still do so with the same technology.
And you wouldn't want to distribute free copies of a file if the author doesn't want you to,
right?
Using media9
Since this package is newer, it's again advisable to check whether you have it installed. If you
cannot typeset the file below, then your TeX distribution needs some updates. The TeXLive
distribution that most people are now using on the Mac lets you do the necessary updates by
simply entering the following commands:
sudo tlmgr update --self
sudo tlmgr update all
The following example again uses the flash animation blendone.swf with the poster frame
FlashPoster.jpg, and the source can be downloaded as media9-swf.tex:
\documentclass{article}
\usepackage{media9}
\usepackage[english]{babel}
\begin{document}
\includemedia[
activate=onclick,
width=0.5\textwidth
]{\includegraphics{FlashPoster.jpg}}{blendone.swf}
\end{document}
When I first tried to include the movie Circle-m-increase3.mp4 from the above example with
media9, the embedded player was unable to display it. A simple fix for this is to run the movie
file through Quicktime Player first: Choose File Export... and select 480p as the format.
If the exported file is called Circle-m-increase3a.move, you can now embed it in your PDF
with this source:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{media9}
\begin{document}
\includemedia[
activate=pageopen,
5 of 6 9/25/2016 12:15 AM
Generating PDF with animations using LaTeX http://pages.uoregon.edu/noeckel/PDFmovie.html
width=200pt,height=170pt,
addresource=Circle-m-increase3a.mov,
flashvars={%
src=Circle-m-increase3a.mov
&scaleMode=stretch}
]{}{StrobeMediaPlayback.swf}
\end{document}
noeckel@uoregon.edu
Last modified: Fri Jun 29 07:44:03 PDT 2012
6 of 6 9/25/2016 12:15 AM