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.
Asked
Active
Viewed 824 times
2 Answers
8
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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)>>
>>}%
%
\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
AlexG
- 54,894
7
\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.
Mica
- 4,629
VPlayer.swfandrandom.mp4frommedia9directory 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\definethe right way to write new commands in ConTeXt? – AlexG Jul 03 '15 at 09:02\deineis okay. I meant that instead of using\embedvideo{width}{height}{extras}{filename}use\embedvideo[filename][width=..., height=..., extras=...]. I'll write the boilerplate code and then post the result here. – Aditya Jul 03 '15 at 14:05width=..., height=..., extras=...would look like optional settings. However,widthandheightare needed to correctly size the widget and therefore should be mandatory arguments. How does ConTeXt distinguish between mandatory and optional arguments? Could you give me some pointer to where this is documented and how to define new commands? – AlexG Jul 30 '15 at 07:55