145

I'm very new to presentations in LaTeX (I've been using PowerPoint for years but have finally converted).

I am wondering how to get a GIF into a section. If need be, I can convert a GIF into lots of pictures and have them overlay to give the impression of movement.

3
  • Yeah, if you mange to convert into "normal" pictures, than it is quite easy to include them with \multiinclude Apr 23, 2015 at 19:20
  • How does one split my gif into images?
    – iluvLatex
    Apr 23, 2015 at 19:34
  • @iluvLatex ffmpeg is the easiest option. ffmpeg -i input/Clap.gif -vsync 0 temp/temp%d.png source Nov 24, 2021 at 12:10

3 Answers 3

145

1. Convert and split animated GIF into PNG sequence

convert -coalesce something.gif something.png

or

magick convert -coalesce something.gif something.png

convert/magick convert is a command line tool from the ImageMagick.org software package. The command name depends on the software version.

This produces a set of numbered PNG files something-0.png, ..., something-16.png (Here, the original GIF https://i.stack.imgur.com/VHJmL.gif, renamed to something.gif consists of 17 frames.) Option -coalesce is necessary to undo a possible optimization of the original GIF file.

2. Get original animation speed

magick identify -verbose something.gif | grep 'Delay'

Users of Windows may want to run

magick identify -verbose something.gif | sls -Pattern 'Delay'

in the PowerShell.

This outputs lines (one for every frame) like:

Delay: 10x100
Delay: 10x100
Delay: 10x100
...

The frame rate (frames per second), to be passed as an argument to the \animategraphics command below, is found by dividing the number after x by the number in front of it:

frame rate = 100 (tics/s) / 10 (tics/frame) = 10 frames/s

3. Embed PNG sequence as an embedded looping animation in the final PDF

(This kind of animation requires a JavaScript-supporting PDF viewer, such as Acrobat Reader or KDE Okular.)

\documentclass{beamer}
\usepackage{animate}

\begin{document}
\begin{frame}{Embedded Animation}
  \animategraphics[loop,controls,width=\linewidth]{10}{something-}{0}{16}
\end{frame}
\end{document}

Argument {10} sets the desired frame rate (frames per second), {0} and {16} set the first and last file numbers of the PNG series to be included in the animation. Note that frame rates above 30 FPS, if at all achieved by the PDF viewer, do not make much sense. 30 FPS is a typical value in video encoding. Use command option measure and the + button to see which frame rates are possible. They may depend on the image size and of course on the hardware on which the PDF viewer is running.

For a more GIF-like impression, option autoplay can be used instead of or in addition to option controls.

enter image description here

28
  • 2
    @user4417 You will also need the most recent animate package version 2016/03/15 .
    – AlexG
    Mar 22, 2016 at 11:11
  • 5
    @Royi The question is rather: Does the PDF standard support APNG? The answer is 'No'. You must convert it into a series of images and use one of the suggested methods (multipage PDF or animate-based animation).
    – AlexG
    Aug 28, 2017 at 15:55
  • 3
    The PDF format and its viewer are Adobe inventions. I think they still define and extend the standard, although PDF is now an ISO standard.
    – AlexG
    Aug 28, 2017 at 16:07
  • 3
    For someone else who stumbles upon this: The {0}{16} describes the first and last frame of the animation. You'll need to identify something.gif to determine how many frames are in the gif Sep 18, 2017 at 17:45
  • 1
    Another observation: identify -verbose something.gif | grep 'Delay' is enough. In fact, prepending magick causes an error. Jul 2, 2018 at 17:09
49

Ok, let's start with the .gif from @SeanAllred comment.

First Step: Converting

There are probably many methods to do so. To be independent of the operation system, there are online converter, ask your favourite search engine for suggestions.

Or if you prefer using the command line use convert from ImageMagick:

convert -coalesce VHJmL.gif something.png

Make sure you resulting images are named something-0 and so on.

Second Step: multiinclude

\documentclass{beamer}
\usepackage{xmpmulti}
\begin{document}
    
    %asuming you images are called "something-0.png" up to "something-16.png" 
    \begin{frame}
        \transduration<0-16>{0}
        \multiinclude[<+->][format=png, graphics={width=\textwidth}]{something}
    \end{frame}
    
\end{document}

enter image description here

22
  • 3
    i.stack.imgur.com/VHJmL.gif Apr 23, 2015 at 22:18
  • 4
    It (the PDF) doesn't loop :-(
    – AlexG
    Apr 24, 2015 at 14:38
  • 13
    I get a slide per png file, but no animation. I can advance the "animation" myself, but then there are pauses and white screens.
    – user4417
    Mar 22, 2016 at 2:35
  • 7
    @Dr.ManuelKuehner The animate approach is very smooth on Linux. Static, in fact. :(
    – cfr
    Jun 10, 2018 at 21:48
  • 2
    @Dr.ManuelKuehner On the other hand, this method is also static - there's just more that is static. :(
    – cfr
    Jun 10, 2018 at 21:52
10

Have a look at pdfpc they have an example how to embed videos. pdfpc is a tool for displaying your beamer presentations.

It doesn't work with gifs but you can still convert something.gif something.avi. To get a preview picture run convert something.gif poster.png

Updated example for using the multimedia package now recommended by pdfpc:

\documentclass{beamer}
\usepackage{multimedia}

\begin{document}
  \frame{
    \movie{\includegraphics{poster.png}}{movie.avi}
  }
\end{document}

Display your presentation with pdfpc my-presentation.pdf

In earlier versions it didn't seem to work if your video was in another directory set by \graphicspath.

5
  • 1
    Have done that: tex.stackexchange.com/a/444158/108331
    – Benjamin
    Aug 1, 2018 at 14:49
  • Couldn't find pdfpc-commands.sty file. Can pdfpc-movie.sty be used instead? Jun 29, 2021 at 18:00
  • @praveenpathak pdfpc seemed to changed some things since I wrote this answer. I edited to reflect these changes as best as I could.
    – Benjamin
    Jul 2, 2021 at 17:39
  • Yes, this works now. Thank you @Benjamin Jul 4, 2021 at 2:08
  • 1
    This also works with Document Viewer on Ubuntu LTS 20 when the PNG and AVI files are both in the working directory.
    – user30850
    Sep 17, 2021 at 10:06

You must log in to answer this question.

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