如何使用 ConTeXt 在 pdf 中嵌入视频?

如何使用 ConTeXt 在 pdf 中嵌入视频?

我听说可以使用 ConTeXt 在 tex 文件和生成的 pdf 文件中嵌入视频。Hans Hagen 在他的手册中非常简要地介绍了视频,但没有 Minexample。我在 wiki 中找不到有关视频的任何信息。

答案1

以下示例定义了\embedvideo。它使用与 LaTeX 包相同的媒体嵌入方法media9MP4/H264音频视频格式在视频播放器组件中播放VPlayer.swf运送media9

查看media9 手册关于如何VPlayer通过 FlashVars 进行配置,它们作为的第 3 个参数传递\embedvideo

可以通过按下鼠标左键(暂停)和释放(播放/恢复)、通过右键单击访问的上下文菜单以及通过键盘(请参阅上下文菜单了解按键)来控制视频播放器。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \embedvideo{<width>}{<height>}{<flashvars>}{<video file (MP4+H264 or FLV)>}
% flashvars documented in `texdoc media9`,  page 19
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\protected\def\pdfobj{\pdfextension obj }
\def\pdflastobj{\numexpr\pdffeedback lastobj\relax}
\protected\def\pdfannot{\pdfextension annot }
\let\pdfxform\saveboxresource
\let\pdflastxform\lastsavedboxresourceindex
\define[4]\embedvideo{%
  \ifdefined\vplayer\else%
    \immediate\pdfobj stream file {VPlayer.swf}%
    \immediate\pdfobj{<<
      /Type/Filespec/F (VPlayer.swf)/UF (VPlayer.swf)
      /EF <</F \the\pdflastobj\space 0 R>>
    >>}%
    \edef\vplayer{\the\pdflastobj}%
  \fi%
  %
  \immediate\pdfobj stream file {#4}%
  \immediate\pdfobj{<<
    /Type/Filespec/F (#4)/UF (#4)
    /EF <</F \the\pdflastobj\space 0 R>>
  >>}%
  \edef\video{\the\pdflastobj}%
  %
  \immediate\pdfobj{<<
    /Type/RichMediaInstance/Subtype/Video
    /Asset \vplayer\space 0 R
    /Params <</Binding/Foreground/FlashVars (source=#4&#3)>>
  >>}%
  %
  \immediate\pdfobj{<<
    /Type/RichMediaConfiguration/Subtype/Video
    /Instances [\the\pdflastobj\space 0 R]
  >>}%
  %
  \immediate\pdfobj{<<
    /Type/RichMediaContent
    /Assets <<
      /Names [(VPlayer.swf) \vplayer\space 0 R (#4) \video\space 0 R]
    >>
    /Configurations [\the\pdflastobj\space 0 R]
  >>}%
  \edef\rmcontent{\the\pdflastobj}%
  %
  \pdfobj{<<
    /Activation <<
      /Condition/PO
      /Presentation <<
        /Transparent true
        /Style/Embedded
        /PassContextClick true
      >>
    >>
    /Deactivation <</Condition/PC>>
  >>}%
  %
  \setbox0=\vbox to #2 {\vss\hbox to #1{\tt #4\hss}\vss}%
  \immediate\pdfxform 0%
  %
  \pdfannot width #1 height #2 depth 0pt {
    /Subtype/RichMedia
    /BS <</W 0/S/S>>
    /Contents (embedded video file:#4)
    /NM (rma:#4)
    /AP <</N \the\pdflastxform\space 0 R>>
    /RichMediaSettings \the\pdflastobj\space 0 R
    /RichMediaContent \rmcontent\space 0 R
  }%
  \hbox to #1 {\vbox to #2 {}\hss}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\starttext
\ConTeXt{} video  example:

top

left\embedvideo{4cm}{3cm}{autoPlay=true&loop=true}{random.mp4}right

bottom
\stoptext

答案2

\pdfcompresslevel=0
\setupinteraction[state=start]
\starttext
\externalfigure[clip.mov][height=2cm, width=2cm, preview=yes]
\stoptext

仅支持 .mov。这与排版图像时使用的代码相同。

相关内容