[Tex/LaTex] gif image in beamer presentation


I wish to display some animations in my beamer presentation. The most trivial way that comes to my mind is to use a gif image. How can I put it in the presentation and what should I use to display it? Is there any other way of doing it?

Best Answer

In a single run you will get 4 separate files as follows,

  • a GIF animation
  • a PDF animation
  • a MP4 video
  • a slide that contains a PDF animation and imports a MP4 video as shown in the figure below

enter image description here


  • ImageMagick must be installed and its path must be registered to PATH system variable.
  • FFMPEG must be installed and its path must be registered to PATH system variable.

How to compile

The following input file, named as main.tex, must be compiled with pdflatex -shell-escape main. WARNING: If your OS is not Windows, then please adapt the Windows shell command to your OS shell command.

% this filename is main.tex
% compile it with "pdflatex -shell-escape main" (without the quotes)



% Create a PDF file that consist of some pages


\immediate\write18{latex frames}
\immediate\write18{dvips frames}
\immediate\write18{ps2pdf frames.ps}
% sometimes you need to disable auto rotate in ps2pdf. Please follow up if you really need it!
% delete auxiliary files generated by the 3 commands above.
\@for\x:={tex,dvi,ps,log,aux}\do{\immediate\write18{cmd /c del frames.\x}}

% convert to GIF animation
\immediate\write18{convert -delay 5 -loop 0 -density 75 -alpha remove frames.pdf Lissajous.gif}

% convert to MP4
\immediate\write18{convert -density 600 -alpha remove frames.pdf frames-\@percentchar04d.png}
\immediate\write18{cmd /c if exist Lissajous.mp4 del Lissajous.mp4}
\immediate\write18{ffmpeg -r 5 -i frames-\@percentchar04d.png -vcodec libx264 Lissajous.mp4}
\immediate\write18{cmd /c if exist frames-*.png del frames-*.png}

% convert to a single PDF animation

\immediate\write18{pdflatex Lissajous}
% delete auxiliary files generated by the above command.
\@for\x:={tex,log,aux}\do{\immediate\write18{cmd /c del Lissajous.\x}}


\begin{frame}[t]{Lissajous in action}
\begin{block}{PDF Animation}
%\animategraphics[controls,autoplay,loop,scale=<integer>]{<frame rate>}{<PDF filename without extension>}{<left blank>}{<left blank>}
        source=Lissajous.mp4%same path as in addresource!
        &autoPlay=true%optional configuration


The auxiliary file named frames.pdf must be removed manually because I cannot remove it from within main.tex. If you know how to do this, let me know!

Related Question