# How to embed videos in pdf with ConTeXt?

I have heard that it is possible to embed videos with ConTeXt in tex-files and in the resulting pdf-file. Hans Hagen wrote very briefly about videos in his manual, but there is no Minexample. I could not find anything about videos in the wiki.

-

The following example defines \embedvideo. It uses the same media embedding method as the media9 LaTeX package. Video files in the MP4/H264 and FLV formats are played back within the video player component VPlayer.swf shipping with media9.

See the media9 manual on how to configure VPlayer via FlashVars, which are passed as the 3rd argument of \embedvideo.

The video player can be controlled by left mouse button press (pause) and release (play/resume), via the context menu accessed by right mouse button click and via the keyboard (see context menu for keys).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \embedvideo{<width>}{<height>}{<flashvars>}{<video file (MP4+H264 or FLV)>}
% flashvars documented in texdoc media9,  page 19
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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

-
Is this also supposed to work on Linux? I downloaded VPlayer.swf and random.mp4 from media9 directory and placed them in the current directory, and compiled your sample file. When I open it in acroread 9.5.1 (Linux 32 bit), I get a pop-up box: "A 3D data parsing error has occured". – Aditya Jun 27 '13 at 22:24
This LaTeX question seems to suggest that AR9.5 does not include a Flash Player. I would need to downgrade AR to AR9.4.1 AND install player_flv_maxi. It might be simpler to just try to install AR using wine :( – Aditya Jun 27 '13 at 22:35
@Aditya: Exactly... – AlexG Jun 28 '13 at 6:41
@Aditya: If you have a full TeXLive installation (with media9) and if you are using VPlayer, you don't need to download it to your current dir. – AlexG Jun 28 '13 at 8:17
Thanks for this. I can confirm that this method works with Adobe Acrobat on MacOS. It will be nice to wrap this around a more ConTeXt-ish interface. – Aditya Jul 2 '15 at 22:03
\pdfcompresslevel=0
\setupinteraction[state=start]
\starttext
\externalfigure[clip.mov][height=2cm, width=2cm, preview=yes]
\stoptext


only .mov is supported. This is the same code you'd use to typeset an image.

-