Media9 将于 2020 年 12 月淘汰。有没有在 LaTeX 中嵌入视频/音频的替代方法?

Media9 将于 2020 年 12 月淘汰。有没有在 LaTeX 中嵌入视频/音频的替代方法?

由于 Adob​​e 放弃对 Flash 的支持,Media9 将于 2020 年 12 月过时。有没有不依赖 Flash 的替代品,可以在 latex 文档中包含视频和音频?

答案1

Adobe 官方关于嵌入式多媒体支持(MP4/h.264 视频、MP3 音频)的 PDF 文档,例如https://helpx.adobe.com/acrobat/using/adding-multimedia-pdfs.html,仍然以 Flash 为中心。因此,Adobe 似乎尚未决定 Flash EOL 之后 PDF 中多媒体的未来。也许他们正在努力,但尚未向公众披露任何信息。

更新 04/2021

这是一个最小的无 Flash 视频嵌入实现,与 Adob​​e 当前向 Acrobat 用户提供的实现非常相似。

在 J. Hagemann、D. Savransky、M. Vlasák 和其他用户的帮助下错误追踪器,可以为 Acrobat Reader 制定一个可接受的解决方案,让用户通过操作系统特定的媒体播放器插件的控件来控制播放。对于也可以在 Okular PDF 查看器中播放的视频,请尝试用户建议的方法弗里茨

为了使其在 Windows 上运行,需要对注册表进行以下调整。不幸的是,必须使用管理员权限才能完成此操作,运行(在文件资源管理器中单击)以下文件(用户找到的信息深蓝):

文件enablePlayerControls.reg

REGEDIT4

[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Adobe\Acrobat Reader\DC\FeatureState]
"HonorControls"=dword:00000001

\embedvideo{<poster text/image>}{<video file>}嵌入带有; 星号变体的视频\embedvideo*{...}{...}以实现自动播放:

\documentclass{article}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \embedvideo{<poster or text>}{<video file (MP4+H264)>}
% \embedvideo*{...}{...}                     % auto-play
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[bigfiles]{pdfbase}
\ExplSyntaxOn
\NewDocumentCommand\embedvideo{smm}{
  \group_begin:
  \leavevmode
  \tl_if_exist:cTF{file_\file_mdfive_hash:n{#3}}{
    \tl_set_eq:Nc\video{file_\file_mdfive_hash:n{#3}}
  }{
    \IfFileExists{#3}{}{\GenericError{}{File~`#3'~not~found}{}{}}
    \pbs_pdfobj:nnn{}{fstream}{{}{#3}}
    \pbs_pdfobj:nnn{}{dict}{
      /Type/Filespec/F~(#3)/UF~(#3)
      /EF~<</F~\pbs_pdflastobj:>>
    }
    \tl_set:Nx\video{\pbs_pdflastobj:}
    \tl_gset_eq:cN{file_\file_mdfive_hash:n{#3}}\video
  }
  %
  \pbs_pdfobj:nnn{}{dict}{
    /Type/RichMediaInstance/Subtype/Video
    /Asset~\video
    /Params~<</FlashVars (
      source=#3&
      skin=SkinOverAllNoFullNoCaption.swf&
      skinAutoHide=true&
      skinBackgroundColor=0x5F5F5F&
      skinBackgroundAlpha=0.75
    )>>
  }
  %
  \pbs_pdfobj:nnn{}{dict}{
    /Type/RichMediaConfiguration/Subtype/Video
    /Instances~[\pbs_pdflastobj:]
  }
  %
  \pbs_pdfobj:nnn{}{dict}{
    /Type/RichMediaContent
    /Assets~<<
      /Names~[(#3)~\video]
    >>
    /Configurations~[\pbs_pdflastobj:]
  }
  \tl_set:Nx\rmcontent{\pbs_pdflastobj:}
  %
  \pbs_pdfobj:nnn{}{dict}{
    /Activation~<<
      /Condition/\IfBooleanTF{#1}{PV}{XA}
      /Presentation~<</Style/Embedded>>
    >>
    /Deactivation~<</Condition/PI>>
  }
  %
  \hbox_set:Nn\l_tmpa_box{#2}
  \tl_set:Nx\l_box_wd_tl{\dim_use:N\box_wd:N\l_tmpa_box}
  \tl_set:Nx\l_box_ht_tl{\dim_use:N\box_ht:N\l_tmpa_box}
  \tl_set:Nx\l_box_dp_tl{\dim_use:N\box_dp:N\l_tmpa_box}
  \pbs_pdfxform:nnnnn{1}{1}{}{}{\l_tmpa_box}
  %
  \pbs_pdfannot:nnnn{\l_box_wd_tl}{\l_box_ht_tl}{\l_box_dp_tl}{
    /Subtype/RichMedia
    /BS~<</W~0/S/S>>
    /Contents~(embedded~video~file:#3)
    /NM~(rma:#3)
    /AP~<</N~\pbs_pdflastxform:>>
    /RichMediaSettings~\pbs_pdflastobj:
    /RichMediaContent~\rmcontent
  }
  \phantom{#2}
  \group_end:
}
\ExplSyntaxOff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{graphicx}

\begin{document}
\section{autoplay}
\embedvideo*{\includegraphics[page=1]{example-movie}}{example-movie.mp4}
\newpage
\section{play on click}
\embedvideo{\includegraphics[page=1]{example-movie}}{example-movie.mp4}
\end{document}

答案2

通过使用屏幕注释以 pdf 格式而不是富媒体注释可以获取播放器配置和播放器交互。我发现以下解决方案满足我的需求:

\documentclass{beamer}
\usepackage{xkeyval}
\usepackage{media9}
\usetheme{CambridgeUS}
\usecolortheme{dolphin}
\usepackage{zref-abspage}

\makeatletter
\define@boolkey{simplemedia}{autoplay}{\def\simplemediaautoplay{#1}}
\define@boolkey{simplemedia}{showGUI}{\def\simplemediashowGUI{#1}}
\presetkeys{simplemedia}{autoplay=true,showGUI=true}{}

% all page-references relate to: Adobe PDF Reference, sixth edition, November 2006, can be found e.g.:
%https://ghostscript.com/~robin/pdf_reference17.pdf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \simplemedia[<options>]{<poster or text>}{<media file>}{MIME type}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn
%\cs_new:Npn\simplemedia[3][]{
\newcommand\simplemedia[4][]{%
  \setkeys{simplemedia}{#1}%
  \leavevmode
  \pbs_pdfobj:nnn{}{fstream}{{}{#3}}
  \pbs_pdfobj:nnn{}{dict}{
    /Type/Filespec/F~(#3)/UF~(#3)
    /EF~<</F~\pbs_pdflastobj:>>
  }
  %
  \pbs_pdfobj:nnn{}{dict}{
      /CT~(#4)% content type, page 764, table 9.9
      /D~\pbs_pdflastobj:% full file spcification, page 764, table 9.9
      /N~(Media~clip~from~#3)% name of media clip, page 764, table 9.8
      /P~<</TF (TEMPACCESS)>>% media permissions, page 764, table 9.9
      /S~/MCD% subtype media-clip-data, page 764, table 9.8
  }
  %
  \pbs_pdfobj:nnn{}{dict}{
      /C~\pbs_pdflastobj:% media clip dictionary, page 762, table 9.6
      /N~(RenditionFrom#3)% name of rendition, page 759, table 9.1
      /P~<<% media play parameters dictionary, page 762, table 9.6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Here's the point to switch on/off player GUI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        /BE~<</C~\simplemediashowGUI~%C: display a player-specific controller user interface, page 769, table 9.15
        /A~true>>~%A: automatically play when activated, page 770, table 9.15
        % select player (not used here)
%        /PL~<</A~[% arrray of media player info objects page 777
%%        <</PID~<</U~(vnd.adobe.swname:ADBE_MCI)~>>~>>~% PID: software identifier object, page 779
%        <</PID~<</U~(vnd.adobe.swname:MSFT_WindowsMediaPlayer)~/OS[(win16)~(win32)~(win9x)~(winnt)~(wince)]>>~>>~%/OS operating system, page 780
%        ]~>>
      ~>>
      /S~/MR% subtype of rendition, page 759, table 9.1
  }
  %
  \tl_set:Nx\mediarendition{\pbs_pdflastobj:}
  %  
  \pbs_pdfobj:nnn{}{dict}{}% obj-number created for later use
  \tl_set:Nx\renditionactionplay{\pbs_pdflastobj:}%
  %
  \pbs_pdfobj:nnn{}{dict}{}% obj-number created for later use
  \tl_set:Nx\renditionactionstop{\pbs_pdflastobj:}%
  %
  \hbox_set:Nn\l_tmpa_box{#2}% size of annotation
  \tl_set:Nx\l_box_wd_tl{\dim_use:N\box_wd:N\l_tmpa_box}
  \tl_set:Nx\l_box_ht_tl{\dim_use:N\box_ht:N\l_tmpa_box}
  \tl_set:Nx\l_box_dp_tl{\dim_use:N\box_dp:N\l_tmpa_box}
  \pbs_pdfxform:nnnnn{1}{1}{}{}{\l_tmpa_box}
  %
  \tl_set:Nx\l_simplem_current_page_tl{\zref@extract{simplem@\int_use:N\g_simplem_id_int}{abspage}}
  \pbs_pdfannot:nnnn{\l_box_wd_tl}{\l_box_ht_tl}{\l_box_dp_tl}{
      /T~(AnnotationFrom#3)~% title of screen annotation, page 640, table 8.38 
      /Subtype~/Screen~% Subtype Sreen, page 616, table 8.20 and page 640, table 8.38
      /BS~<</W~1/S/S>>% Borderstyle
      /C~[0.039216~0.039216~0.039216]% color used background, title bar, border, page 607, table 8.15
      /Contents~(EmbeddedAudiofile#3)% Text to be displayed, page 606, table 8.15
      /NM~(audioscreenannot:#3)% annotation name, page 606, table 8.15
      /AP~<</N~\pbs_pdflastxform:>>% appearance dictionary, page 606, table 8.15
      /F~4~%Annotation flag, page 606, table 8.15 and page 608, table 8.16
      /A~\renditionactionplay~% Action to be performed, page 640 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Here's the point to switch on/off autoplay
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      % autoplay is realised by "additional action" (page 640), 
      % PageOpen (PO) -> play "Play Rendition"
      % PageClose (PC) -> play "Stop Rendition" (see page 650)
      /AA~<<\ifKV@simplemedia@autoplay~/PO~\renditionactionplay~\fi~/PC~\renditionactionstop~>>~%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       see Adobe pdfmark-reference, I THINK, THIS WORKS ONLY WITH tex->dvips->ps2pdf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \int_compare:nT{\l_simplem_current_page_tl>0}{
        /P~\exp_args:Ne\pdf_pageobject_ref:n{\l_simplem_current_page_tl}
      }
      /CA~1%constant opacity value, page 618
  }
  % Rendition Action: "Play Rendition"
  \pbs_pdfobj:nnn{\renditionactionplay}{dict}{%
      /R~\mediarendition%
      /S~/Rendition
      /OP~4%operation to perform (page 669): 4 = play rendition specified by R
      /AN~\pbs_pdflastann:%
  }
  % Rendition Action: "Stop Rendition"
  \pbs_pdfobj:nnn{\renditionactionstop}{dict}{%
      /R~\mediarendition%
      /S~/Rendition
      /OP~1%operation to perform (page 669): 1 = stop rendition specified by R
      /AN~\pbs_pdflastann:%
  }
  %
  \phantom{#2}
  \zref@labelbyprops{simplem@\int_use:N\g_simplem_id_int}{abspage}
  \int_gincr:N\g_simplem_id_int
}%
\int_new:N\g_simplem_id_int
\ExplSyntaxOff
\makeatother

\begin{document}
\begin{frame}{Video inclusion with autoplay and showGUI}
\begin{columns}
\begin{column}[t]{128mm}
\begin{itemize}
\item command:\\
\scriptsize 
\texttt{\textbackslash{}simplemedia\{\textbackslash{}vbox to 3cm\{\textbackslash{}vfil\textbackslash{}hbox to 5cm\{\}\textbackslash{}vfil\}\}\{sample-5s.mp4\}\{video/mp4\}}
\normalsize
\item result:
\simplemedia{\vbox to 3cm{\vfil\hbox to 5cm{}\vfil}}{sample-5s.mp4}{video/mp4}
\hspace{0.5cm}\tiny{}https://samplelib.com/sample-mp4.html
\end{itemize}
\end{column}
\end{columns}
\end{frame}


\begin{frame}{Audio inclusion with autoplay and GUI}
\begin{columns}
\begin{column}[t]{128mm}
\begin{itemize}
\item command:\\
\scriptsize 
\texttt{\textbackslash{}simplemedia\{My audio\}\{sample-6s.mp3\}\{audio/mp3\}}
\normalsize
\item result:
\simplemedia{My audio}{sample-6s.mp3}{audio/mp3}
\hspace{0.5cm}\tiny{}https://samplelib.com/sample-mp3.html
\end{itemize}
\end{column}
\end{columns}
\end{frame}

\begin{frame}{Audio inclusion with autoplay, no GUI}
\begin{columns}
\begin{column}[t]{128mm}
\begin{itemize}
\item command:\\
\scriptsize 
\texttt{\textbackslash{}simplemedia[showGUI=false]\{My audio\}\{sample-6s.mp3\}\{audio/mp3\}}
\normalsize
\item result:
\simplemedia[showGUI=false]{My audio}{sample-6s.mp3}{audio/mp3}
\hspace{0.5cm}\tiny{}https://samplelib.com/sample-mp3.html
\end{itemize}
\end{column}
\end{columns}
\end{frame}

\begin{frame}{Audio inclusion without autoplay}
\begin{columns}
\begin{column}[t]{128mm}
\begin{itemize}
\item command:\\
\scriptsize 
\texttt{\textbackslash{}simplemedia[autoplay=false]\{Klick here to start\}\{sample-6s.mp3\}\{audio/mp3\}}
\normalsize
\item result:
\simplemedia[autoplay=false]{Klick here to start}{sample-6s.mp3}{audio/mp3}
\hspace{0.5cm}\tiny{}https://samplelib.com/sample-mp3.html
\end{itemize}
\end{column}
\end{columns}
\end{frame}

\end{document}

它基于上述无 flash 示例,可与 latex->dvips->ps2pdf 配合使用,感谢 AlexG 还与 pdflatex 配合使用(lualatex 和 xelatex 也应该可以工作)。pdf 文件可与我实际的 Acrobat Reader DC 和 Foxit Reader 一起播放(均在 Windows 下)。我的 Acobat XI(2012 年)不支持 mp4,只能播放 mp3 示例。在所有情况下,您都必须先信任该文档。

问候,弗里茨

答案3

详细说明这里这里Flash 支持已停止。但是,Adobe Reader DC(我使用的是版本 21.001.20142)可以获取使用 mp4 视频编译的 pdf 文档。

在我的文档中,我使用了 media9 包中的以下代码片段:

        \includemedia[
    width=0.6\linewidth,
    height=0.7\linewidth,
    keepaspectratio,
    activate=pageopen,
    playbutton=fancy,
    addresource=figures/80deg90.mp4,
    flashvars={source=figures/80deg90.mp4&autoPlay=true}
    ]{}{VPlayer.swf}

我得到了一个编译好的 pdf。一开始我无法在 Adob​​e Reader DC 中看到视频,但使用中提到的设置这里,我让它工作了:

 1. Go to Windows Settings > Display > Graphic Settings > Under Choose an App/ Browse >
 2. Add Acrobat.exe and edit the default from "Let Windows decide" to Power Saving Intel.
 3. Relaunch Acrobat.
 4. Try to play video. 

上一个答案的完整解决方案,你会发现这里在 overleaf 中运行。我也可以编译该文档并在 Adob​​e Reader DC 中运行它。

相关内容