Embed GIF and MP4 in LaTeX Beamer

As an research postgraduate student, I frequently make "academic-looking" slides for meetings, which comprise a lot of references, tables, charts, and sometimes math equations. LaTeX is excellent for typesetting these elements, so using LaTeX to make slides sounds like a good idea.

With tutorials like Beamer - Overleaf, I got started with this approach and feel more and more comfortable. I even made a series of templates for me and my friends (for more details: Beamer-LaTeX-Themes). Here are some example pages:

PolyU
math

However, LaTeX only generates PDF files, which are usually static. Excluding videos and GIFs completely from your presentation? How pitiful. I searched the internet for a while and eventually found a simple workflow to embed GIFs in LaTeX beamer 1.

Convert gif/mp4 to png series

Firstly, use the command-line tool to convert .gif/.mp4 to a series of .png:

magick convert -coalesce <>.gif <>.png
magick convert -coalesce <>.mp4 <>.png

P.S. If the folder only have one gif/mp4 and the desired output image name is fig-<>.png:

magick convert -coalesce *.gif fig.png
magick convert -coalesce *.mp4 fig.png

P.S. If you want to index the figures with 3 (or more) digits, such as fig001.png, you can revised the command as:

magick convert -coalesce *.gif fig%3d.png

P.S. When converting other files to .gif, if you want it to loop for infinity times, add option -loop 0.

Embedded them to the beamer

And then add the series of .png as dynamic images in beamer using the animate package:

\usepackage{animate}
...
\animategraphics[loop, autoplay, controls, width=\textwidth]{10}{images/test/test-}{0}{16}

P.S. Sometimes format conversion, batch cropping, and resizing of videos/images are also needed. Following is some useful materials:

ffmpeg + ImageMagick: convert video to GIF by using Terminal.app in macOS - Sergey Nikishkin

How to crop an image using ImageMagick from the command line? - StackExchange

Batch compression of images:

Recommended PDF reader

The generated PDF file can be displayed in Acrobat Reader or Foxit Reader. However, when in full-screen slideshow mode (on MacBook πŸ’» ), the previous one gets blurred and the latter one has a white margin.

Eventually, I found that the best way to display slideshow was:

  • Open the generated .pdf with with Acrobat Reader.
  • Acrobat Reader - Preference - General uncheck Open documents as new tabs in the same window.
  • View - Page Display - Single Page View.
  • Use the read mode by pressing βŒƒ + ⌘ + H and then press βŒƒ + ⌘ + F to enter MacOS's full screen mode.

Footnotes

  1. This workflow was inspired by: Getting GIF and/or moving images into a LaTeX presentation - StackExchange ↩

Lastly updated: 2023-07-16

Do you have any ideas or comments? Please join the discussion on XπŸ‘‡