[Tex/LaTex] Media9 is becoming obsolete Dec 2020. Any alternatives for embedding video/audio in LaTeX

media9video

Media9 is becoming obsolete Dec 2020 due to Adobe dropping Flash support. Is there any replacement out there that does not rely on Flash that will allow the inclusion of video and audio in latex documents?

Best Answer

Official Adobe documents on embedded multimedia support (MP4/h.264 video, MP3 audio) in PDF, such as https://helpx.adobe.com/acrobat/using/adding-multimedia-pdfs.html, are still Flash-centric. Thus, it seems Adobe have not yet decided on the future of multimedia in PDF beyond Flash EOL. Maybe, they are working on it, but nothing has been disclosed to the public yet.

Update 04/2021

Here is a minimal Flash-free implementation of video embedding, which is very similar to the one Adobe themselves currently have to offer to their users of Acrobat.

With the help of users J. Hagemann, D. Savransky, M. Vlasák and others in the bug tracker, an acceptable solution could be put together for Acrobat Reader, that allows the user to control playback through the controls of the OS specific media player plug-in. For video that also plays in the Okular PDF viewer, try the method suggested by user Fritz.

To get it working on Windows, the following tweak of the Registry is necessary. Unfortunately, it must be done with Administration privileges, running (clicking in the file explorer) the following file (information found by user Deepblue):

File enablePlayerControls.reg:

REGEDIT4

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

Embedding a video with \embedvideo{<poster text/image>}{<video file>}; starred variant \embedvideo*{...}{...} for autoplay :

\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}
Related Question