![MP4 以无损方式呈现](https://linux22.com/image/432896/MP4%20%E4%BB%A5%E6%97%A0%E6%8D%9F%E6%96%B9%E5%BC%8F%E5%91%88%E7%8E%B0.png)
我正在使用 beamer 类准备演示文稿,我想添加 mp4 视频。不幸的是,我尝试的所有方法似乎都失败了:
- 尝试:使用
\movie
命令,pdflatex
然后 okular:不起作用,因为 okular 有缺陷,有时播放的视频太小。 - 尝试:使用 htlatex。htlatex 是破碎的。
- 尝试:使用
\movie
,使用构建
latex $name
latex $name
dvisvgm --font-format=woff --exact --zoom=-1 -p1,- $name
并使用 Chromium 打开它。Chromium 显示幻灯片,但不会播放视频。
有没有不破损的方法?
更新:
Alex G 的回答是:
$ dvisvgm --exact --zoom=-1 --font-format=woff2 --output=%f-%0p.svg main
pre-processing DVI file (format version 2)
processing page 1
graphic size: 455.24408pt x 256.074799pt (159.999995mm x 89.999998mm)
output written to main-1.svg
1 of 4 pages converted in 0.343285 seconds
更新:可以使用参数修复此--page
问题。
但自动播放仍然不起作用。
答案1
对于 SVG 格式的演示,您可以media4svg
尝试一下包。
排版如下:
dvilualatex name
dvilualatex name
dvisvgm --bbox=papersize --font-format=woff2 --zoom=-1 --page=- --output=%f-%0p.svg name
name-1.svg
并在(Chrome、Firefox 等)浏览器中打开。
以下是示例(来源) 随包装提供 (单击以查看其运行情况):
\documentclass[dvisvgm,hypertex,aspectratio=169]{beamer}
\usepackage[british]{babel}
\usefonttheme{serif}
\usepackage[T1]{fontenc}
\usepackage{media4svg}
\usepackage{menukeys,siunitx,calc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PageDown, PageUp key event handling; navigation symbols <--, -->
% mouse cursor autohide on idle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[totpages]{zref}
\usepackage{fontawesome5}
\setbeamertemplate{navigation symbols}{}
\def\navBtnSize{9pt}
\def\navBtnLnWd{1.6pt}
\AtBeginShipout{%
\AtBeginShipoutAddToBox{%
\special{dvisvgm:raw
<style>svg{cursor: none}</style>%
<defs>%
<script type="text/javascript">%
<![CDATA[%
var svgRoot=document.getElementsByTagName('svg')[0];%
var cursorTimer;%
document.addEventListener('mousemove', function(e){%
e.preventDefault();e.stopPropagation();%
svgRoot.style.cursor='initial';%
if(e.target!=svgRoot){%
e.target.style.cursor='inherit';%
}%
try{clearTimeout(cursorTimer);}catch(err){};%
cursorTimer=setTimeout(function(){e.target.style.cursor='none';},3000);%
});%
document.addEventListener('keydown',function(e){%
if(e.key=='PageDown'||e.key=='ArrowDown'||e.key=='ArrowRight'){%
\ifnum\thepage<\ztotpages
document.location.replace('\jobname-\the\numexpr\thepage+1\relax.svg');%
\fi%
}else if(e.key=='PageUp'||e.key=='ArrowUp'||e.key=='ArrowLeft'){%
\ifnum\thepage>1
document.location.replace('\jobname-\the\numexpr\thepage-1\relax.svg');%
\fi%
}%
});%
]]>%
</script>%
</defs>%
}%
}%
\AtBeginShipoutUpperLeftForeground{%
\raisebox{-\dimexpr\height+0.5ex\relax}[0pt][0pt]{\makebox[\paperwidth][r]{%
\normalsize\color{structure!40!}%
\ifnum\thepage>1%
\href{\jobname-\the\numexpr\thepage-1\relax.svg}{\faArrowLeft}%
\else%
\textcolor{lightgray}{\faArrowLeft}%
\fi\hspace{0.5ex}%
\ifnum\thepage<\ztotpages%
\href{\jobname-\the\numexpr\thepage+1\relax.svg}{\faArrowRight}%
\else%
\textcolor{lightgray}{\faArrowRight}%
\fi%
\hspace{0.5ex}%
}}%
}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{Presentation example with embedded video}
\subtitle{Use a Web browser and press \keys{F11}}
\author{AlexG}
\date{\today}
\begin{document}
\selectlanguage{british}
\begin{frame}[fragile]
\titlepage\footnotesize
\makebox[0.3\linewidth]{\hrulefill}\\[1ex]
Navigate with \keys{PageUp} \& \keys{PageDn}, toggle Full-Screen with \keys{F11}.\\[2ex]
To build this presentation from the source, run:\vspace{-2ex}
\begin{verbatim}
dvilualatex beamer-example
dvilualatex beamer-example
dvisvgm --bbox=papersize --font-format=woff2 --zoom=-1 --page=- --output=%f-%0p.svg \
beamer-example
\end{verbatim}
\end{frame}
\begin{frame}[fragile]{Video file}
Embedded local video file from package \emph{mwe}
\begin{verbatim}
\includemedia[width=24em,height=13.5em]{}{example-movie.mp4}
\end{verbatim}
\begin{center}
\includemedia[width=24em,height=13.5em]{}{example-movie.mp4}
\end{center}
\end{frame}
\begin{frame}[fragile]{Remote video}
Video streamed from URL
\begin{verbatim}
\includemedia[width=24em,height=13.5em,url]{}{%
https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm}
\end{verbatim}
\begin{center}
\includemedia[width=24em,height=13.5em,url]{}{https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm}
\end{center}
\end{frame}
\begin{frame}[fragile]{Player control}
The standard player controls (option `\verb+controls+') take a lot of space of the media display. Therefore, it is not recommended to enable them. Nevertheless, interactivity is still provided through touch or left mouse button click, and through the keyboard as summarized in the table.
Click on the media display to start playback. To pause playback, press the left mouse button on the media display. Release it to resume playback. To pause playback permanently, press the left mouse button on the media display and move the mouse out while keeping the button pressed.
\begin{minipage}[t]{0.5\linewidth}
\rule{1ex}{0pt}\\
\begin{tabular}{ll}\hline
Command & Shortcut\\\hline
\rule{0pt}{2.4ex}Toggle Play/Pause & \keys{\SPACE}\\
Increase volume & \keys{\arrowkeyup}\\
Decrease volume & \keys{\arrowkeydown}\\
Unmute audio & \keys{Ctrl+\arrowkeyup}\\
Mute audio & \keys{Ctrl+\arrowkeydown}\\
Toggle Full-Screen & \keys{F11}
\end{tabular}
\end{minipage}%
\begin{minipage}[t]{0.5\linewidth}
\rule{1ex}{0pt}\\
\begin{tabular}{ll}\hline
Command & Shortcut\\\hline
\rule{0pt}{2.4ex}Seek back \SI{1}{\percent} & \makebox[\widthof{\keys{\SPACE}}][l]{\keys{\arrowkeyleft}}\\
Seek forward \SI{1}{\percent} & \keys{\arrowkeyright}\\
Seek back \SI{10}{\percent} & \keys{Ctrl+\arrowkeyleft}\\
Seek forward \SI{10}{\percent} & \keys{Ctrl+\arrowkeyright}\\
Seek to beginning & \keys{Home}\\
Seek to end & \keys{End}
\end{tabular}
\end{minipage}
\end{frame}
\end{document}
笔记:为了使视频在打开页面时自动播放,必须同时将其静音。这是出于安全原因。因此,,autoplay,muted
必须将 添加到 的选项列表中\includemedia...
。(请参阅texdoc media4svg
。)