212

I'm aware that it's possible to embed some kinds of videos and animations in LaTeX files (using the beamer or prosper classes) but I couldn't locate good documentation on this. My web searches returned a list of scattered forum questions and answers.

Could anybody give a link to some help or documentation page that systematically deals with the various ways of embedding videos and animations, the file types that work, etc.?

6 Answers 6

120

I'm personally only familiar with doing this in Beamer, which uses the multimedia package, distributed as part of Beamer itself. (Although it can be used in normal documents as well, independently from the rest of Beamer) The canonical reference on how to use the multimedia package is the Beamer user's guide, section 14.1, but basically it boils down to using the command

\movie[options]{placeholder box}{movie filename}

The placeholder box is some text or other content (could be an image, for example) that determines the size at which the multimedia file is shown.

The multimedia file can be shown either with an external viewer application, which launches when you click on the appropriate part of the PDF file, or directly in the PDF viewer itself. In both cases, though, this functionality is only supported by certain PDF viewers, mostly Adobe Reader. The file types it is able to display depend on the capabilities of the PDF viewer, or if using an external viewer, on which viewer program is being used.

A quick search on CTAN turns up a possible alternative, media9 (which supersedes the old movie15 package). According to the documentation, its main command is

\includemedia[options]{alt content}{media file}

and it seems to offer some of the same main features as Beamer's multimedia. However, I've never used this one myself so I can't say anything about it that isn't mentioned in the package documentation.

9
  • 3
    I've had good luck using the movie15 package, although it does seem to require Acrobat Reader to play the movies. Maybe some other viewers will work, but you definitely can't count on it in general. A nice feature is the ability to define a 'poster' image that takes the place of the movie when the movie is inactive. This way you can still have something meaningful on the slide if it turns out your viewer can't play the movie. Aug 12, 2010 at 1:10
  • 1
    @Michael: The problem is that PDFs with embedded multimedia use Adobe's Rich Media extensions, which are not widely supported, to say the least. In fact, I don't know of any independent codecs for it, although Adobe do have a plugin that can be embedded in other software, and is embedded in MS Power-Point. Aug 12, 2010 at 13:28
  • 2
    Perhaps I'm the only one, but it took me a few error messages to realize multimedia is not automatically loaded by beamer, its distribution means notwithstanding.
    – user17829
    Mar 12, 2014 at 18:37
  • 1
    Funny enough under Crunchbang Waldorf and using multimedia Okular plays the embedded .mp4 where acroread complains that it cannot find the movie file and asks whether I want to pick a replacement.
    – jshlke
    Jan 5, 2015 at 9:40
  • 3
    According to the Beamer documentation cited, this does not "embed" the video in the sense that it is included in the PDF file. It really just provides a link, and the video file needs to be present separately from the PDF. I need to submit a presentation to a conference, and apparently I am able to upload only one file, so this is not a satisfactory solution. Is there a way to truly embed the PDF, so I have a single file?
    – Liam
    Aug 21, 2016 at 14:29
40

There's mention of the movie15 package in one of the other answers. The package movie15 is marked obsolete and has been replaced by the media9 package.

There's a nice example of how to use the media9 package here:

Animations with movie15 and swf files

Two other possibilities are beamer, and yt4pdf (for youtube videos), neither of which I've tried yet.

I've had mixed luck with the default player, VPlayer.swf when using the media9 package (it worked fine with the .avi's I used when trying movie15, but not so well on all the ffmpeg generated .mp4's required for media9). StrobeMediaPlayback.swf (recommended in the question above) appears to be more reliable. It also has some nice features like detachable player windows and fullscreen options.

2
  • Which were the symptoms of the failed attempts? yt4pdf wants Acrobat for producing the pdf.
    – AlexG
    Apr 2, 2012 at 7:22
  • the pdflatex invokation goes without error, but of the four .mp4's that I tried, two show as only images, and the other two display correctly as video. I'm able to play the .mp4's with windows media player without trouble and generated all of them in the same way (using mathematica to generate .avi's and then ffmpeg to convert the .avi's to .mp4's). Apr 3, 2012 at 3:30
30

I personally use hyperref package to start animations and movies during the presentation. This is the snippet of code from one of my Powerdot slides

\begin{center}
\href{run:/usr/local/bin/mplayer -fs forced_pendulum.mp4}{
\includegraphics[scale=0.25]
{forced_pendulum.eps}}
\end{center}

One caveat is that the code lunches MPlayer which plays video but the video is not "embedded" into the slide. I am guessing that I can fix that playing little bit with PSTricks code. In particularly animations done in the pure PostScript should not have any troubles running embedded. The upshot of my approach is that it should work on any class of LaTeX presentations and that doesn't require any particular PDF viewer (mupdf in my case) or any particular operating system for that matter.

3
  • 11
    That also requires the user to have mplayer installed to that specific location. Wouldn't calling the default player for that filetype be a better option?
    – Canageek
    Jul 24, 2012 at 2:50
  • 5
    @Canageek absolutely correct observation. I used absolute path on my machine to "improve security". Executing scripts from PDF documents is not exactly the safest thing to do. I agree with you the above is the most simplistic solution and can be easily improved a lot. Jul 24, 2012 at 21:25
  • 2
    Just to be clear, using the default player would look something like this: \href{run:./animation.avi}{\includegraphics{animation_thumbnail}}
    – Paul Wintz
    Aug 26, 2020 at 11:54
13

The flashmovie package allows you to embed flash movies in pdfLaTeX documents. You need Acrobat Reader 9 to view the documents.

13

I recommend using

\usepackage{media9}%
\newcommand{\includemovie}[3]{%
\includemedia[%
width=#1,height=#2,%
activate=pagevisible,%
deactivate=pageclose,%
addresource=#3,%
flashvars={%
src=#3 % same path as in addresource!
&autoPlay=true % default: false; if =true, automatically starts playback after activation (see option ‘activation)’
&loop=true % if loop=true, media is played in a loop
&controlBarAutoHideTimeout=0 %  time span before auto-hide
}%
]{}{StrobeMediaPlayback.swf}%
}% end of the new command

in the preamble and

\frame[label=blah]{
\begin{center}%
    \includemovie{.85\textheight}{.85\textheight}{movie.mp4}%
\end{center}%
\note{%
    \begin{itemize}
        \item blah
        \item blah
    \end{itemize}
    }%
}%

to produce a slide with a movie.

Background. I was used to the simplicity of movie15 but this was superseded by movie 9. This command provides with a "backward compatible" syntax with all the novelty of movie9.

10

One possibility is to use the animate package.

There is a nice pile of examples showing animate usage over on TeXample.

1
  • 1
    The "animate" link is broken.
    – Paul Wintz
    Aug 11, 2020 at 9:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .