我希望在我的 Beamer 演示文稿中显示一些动画。我想到最简单的方法是使用 gif 图像。我该如何将其放入演示文稿中以及我应该使用什么来显示它?还有其他方法吗?
答案1
一次运行你将获得 4 个单独的文件,如下所示,
- GIF 动画
- PDF 动画
- MP4 视频
- 包含 PDF 动画的幻灯片,并导入 MP4 视频,如下图所示
要求
- 必须安装 ImageMagick 并且其路径必须注册到 PATH 系统变量中。
- 必须安装 FFMPEG 并且其路径必须注册到 PATH 系统变量。
如何编译
以下输入文件名为main.tex
,必须用 进行编译pdflatex -shell-escape main
。警告:如果您的操作系统不是 Windows,那么请将 Windows shell 命令调整为您的操作系统 shell 命令。
% this filename is main.tex
% compile it with "pdflatex -shell-escape main" (without the quotes)
\documentclass[mathserif]{beamer}
\usepackage{filecontents}
% Create a PDF file that consist of some pages
\begin{filecontents*}{frames.tex}
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\multido{\i=5+5}{72}
{
\begin{pspicture}[showgrid=false](-2,-2)(2,2)
\psparametricplot[algebraic,plotpoints=1000,linecolor=red]{0}{\i}{2*sin(7*t*Pi/180)|2*cos(11*t*Pi/180)}
\end{pspicture}
}
\end{document}
\end{filecontents*}
\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.
\makeatletter
\@for\x:={tex,dvi,ps,log,aux}\do{\immediate\write18{cmd /c del frames.\x}}
\makeatother
% convert to GIF animation
\immediate\write18{convert -delay 5 -loop 0 -density 75 -alpha remove frames.pdf Lissajous.gif}
% convert to MP4
\makeatletter
\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}
\makeatother
% convert to a single PDF animation
\begin{filecontents*}{Lissajous.tex}
\documentclass[preview,border=12pt]{standalone}
\usepackage{animate}
\begin{document}
\animategraphics[controls,loop,autoplay,scale=1]{10}{frames}{}{}
\end{document}
\end{filecontents*}
\immediate\write18{pdflatex Lissajous}
% delete auxiliary files generated by the above command.
\makeatletter
\@for\x:={tex,log,aux}\do{\immediate\write18{cmd /c del Lissajous.\x}}
\makeatother
\usepackage{animate,media9}
\begin{document}
\begin{frame}[t]{Lissajous in action}
\begin{columns}[T]
%=============
\begin{column}{0.5\textwidth}
\begin{block}{PDF Animation}
%\animategraphics[controls,autoplay,loop,scale=<integer>]{<frame rate>}{<PDF filename without extension>}{<left blank>}{<left blank>}
\animategraphics[controls,autoplay,loop,scale=1]{10}{frames}{}{}
\end{block}
\end{column}
%=============
\begin{column}{0.5\textwidth}
\begin{block}{MP4}
\includemedia[
activate=onclick,
width=\linewidth,height=\linewidth,
addresource=Lissajous.mp4,
flashvars={%
source=Lissajous.mp4%same path as in addresource!
&autoPlay=true%optional configuration
&loop=true%variables
}
]{}{VPlayer.swf}
\end{block}
\end{column}
%=============
\end{columns}
\end{frame}
\end{document}
笔记:
frames.pdf
必须手动删除名为的辅助文件,因为我无法从 内将其删除main.tex
。如果您知道如何操作,请告诉我!
答案2
不使用外部文件也一样(pdf 在这里:http://perce.de/temp/anim0.pdf):
\documentclass[mathserif]{beamer}
\usepackage{pst-plot,animate}
\begin{document}
\begin{frame}[t]{Lissajous in action}
\begin{columns}[T]
\begin{column}{0.5\textwidth}
\begin{animateinline}[%
width=0.9\linewidth,
begin={\begin{pspicture}(-2.1,-2.1)(2.1,2.1)},
end={\end{pspicture}},
controls, %palindrome, %autoplay
]{3}
\multiframe{72}{iA=50+50,iB=5+5}{
\psset{algebraic,plotpoints=\iA,linecolor=red}
\parametricplot{0}{\iB}{2*sin(7*t*Pi/180)|2*cos(11*t*Pi/180)}
}
\end{animateinline}
\end{column}
\begin{column}{0.5\textwidth}
\begin{align}
x(t)&=2\sin(7t)\\
y(t)&=2\cos(11t)
\end{align}
\end{column}
\end{columns}
\end{frame}
\end{document}