summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/flashmovie/flashmovie.sty
blob: b2f6f9a27c48cb40b1fd84f9ac64308a31b66ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
%%%%%%%%%%%%% flashmovie.sty
%%%%%%%%%%%%% Copyright 2009 Timo Hartmann
%
% Version 0.0
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This package allows direct embedding of flash movies into PDF files. It is
% designed for use with pdflatex.
%
% Basically it uses the fact that the Adobe Reader 9 contains an embedded Adobe Flash 
% player which can be invoked with the "rich media annotation" feature which is described 
% in "Adobe Supplement to the ISO 32000 BaseVersion: 1.7 ExtensionLevel: 3".
%
% advantages:
%   - You can directly embed videos into the pdf (external window is optimal and not necessary).
%   - You can play back videos without worrying about platform dependencies.
%
% disadvantages:
%   - You can only play back embedded videos with Adobe Reader 9 and upwards.
%
% example (1)
%   - download a video file to use, for example
%        http://heasarc.gsfc.nasa.gov/Videos/historical/saturn5.avi
%   - transform this video into the flash format with ffmpeg:
%        ffmpeg -i saturn5.avi saturn5.swf
%     (or use any other program captable of this, for example mencoder)
%   - put following line into your tex-file:
%        \flashmovie[width=10cm,heigth=10cm]{saturn5.swf}
%     (both width and height are needed!)
%   - translate with pdflatex
%   - advantages:
%     - easy
%     - does not reley on external compontents
%   - disadvantages:
%     - ffmpeg is incaptable of embedding h.264 into swf-files, so one can only 
%       use inferior video codecs (sorenson h.263 aka flv,...).
%     - no controls (play,pause,stop,seek,...) possible
%
% example (2)
%   - warning: The following example assumes that you have obainted VideoPlayer.swf
%     and SkinOverPlaySeekStop.swf from Acrobat 9 Pro and put it into the working
%     directory.
%   - download a video file to use, for example
%        http://heasarc.gsfc.nasa.gov/Videos/historical/saturn5.avi
%   - transform this video into the mp4 format with ffmpeg:
%        ffmpeg -i saturn5.avi -vcodec libx264 -vpre hq -crf 22 -acodec libfaac -ab 128k -ac 2 saturn5.mp4
%     (or use any other program captable of this, for example mencoder)
%   - alternatively the flv-format with video-codec sorenson h.263 (aka flv) and audio-codec mp3 is also possible:
%       mencoder saturn5.avi -o saturn5.flv -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=300:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050 -ofps 24 -vf harddup -oac mp3lame -lameopts abr:br=56 )
%     (or use ffmpeg to do the same thing...)
%   - put following line into your tex-file:
%        \flashmoviex[width=10cm,heigth=10cm]{saturn5.mp4}
%     (both width and height are needed! instead of saturn5.mp4 one can also use saturn5.flv but not saturn5.swf)
%   - translate with pdflatex
%   - advantages:
%     - controls (play,pause,stop,seek,...) possible
%     - superior video codec possible (h.264)
%     - one can directly embed mp4 and flv files without conversion
%   - disadvantages:
%     - use of external non-free components.
%
% todo:
%   - replace VideoPlayer.swf and SkinOverPlaySeekStop.swf by some freely available software.
%     it should be possible to program a simple video player with flexsdk and activescript.
%     the videoplayer should play mp4 and flv files and should and be captable of play,pause,seek,stop.
%     controls should be hidable.
%   - make more options of richmedia annotations usable, for example activation by clicking, playcount,...
%   - display a picture when the player is deactivated.
%   - efficient multiple inclusion of video files.
%
% warning:
%   - Because the file names of the movies are directly embedded into the PDFs please use only
%     "normal" file names. More specific use only names compatible with internal PDF strings.
%     There is even a specification what conforming file names are (see the PDF reference).

\RequirePackage{keyval}

\def\flashmovieparamsclear{
  \def\flashmoviewidth {4cm}
  \def\flashmovieheight{4cm}
}

\define@key{flashmovieparams}{width}  {\def\flashmoviewidth  {#1}}
\define@key{flashmovieparams}{heigth} {\def\flashmovieheight {#1}}

\def\flashmovieembedfile#1{
  \immediate
  \pdfobj stream
     attr {  /Type/EmbeddedFile  }
     file {#1}
  \immediate
  \pdfobj { << 
      /Type /Filespec
      /F  (#1)
      /UF (#1)
      /EF << /F \the\pdflastobj\space 0 R >>
    >>}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\flashmovie{\@ifnextchar[\@flashmovie{\@flashmovie[]}}

\def\@flashmovie[#1]#2{\flashmovieparamsclear \setkeys{flashmovieparams}{#1}{
  \newcount\filespecnum
  \newcount\configurationnum
  \newcount\contentnum
  \newcount\settingsnum

  \flashmovieembedfile{#2}
  \filespecnum=\pdflastobj

  \immediate
  \pdfobj
    {<<
      /Instances
        [<<
          /Asset \the\filespecnum\space 0 R
          /Params << /Binding /Foreground >>
        >>]
      /Subtype /Flash
    >>}
  \configurationnum=\pdflastobj

  \immediate
  \pdfobj
    {<<
      /Assets << /Names [(#2) \the\filespecnum\space 0 R] >>
      /Configurations [\the\configurationnum\space 0 R]
    >>}
  \contentnum=\pdflastobj

  \immediate
  \pdfobj
    {<<
      /Activation 
        << /Type /RichMediaActivation 
           /Condition /PO 
           /Configuration \the\configurationnum\space 0 R 
           /Animation 
             << /Subtype /Linear 
                /Speed 1 
                /Playcount 1 
             >> 
           /Presentation
             << /PassContextClick false
                /Style /Embedded 
                /Toolbar false
                /NavigationPane false
                /Transparent true
                /Window 
                  << /Type /RichMediaWindow 
                     /Width  << /Default 100 /Min 100 /Max 100 >> 
                     /Height << /Default 100 /Min 100 /Max 100 >> 
                     /Position 
                       << /Type /RichMediaPosition 
                          /HAlign /Near 
                          /VAlign /Near 
                          /HOffset 0 
                          /VOffset 0 
                       >> 
                  >> 
              >> 
        >> 
      /Deactivation 
        << /Type /RichMediaDeactivation 
           /Condition /XD 
        >> 
    >>}
  \settingsnum=\pdflastobj

  \newlength{\xxwidth}
  \newlength{\xxheight}
  \newsavebox{\xxcontent}

  \sbox{\xxcontent} {{\hbox to \flashmoviewidth {\vbox to \flashmovieheight { }}}}

  \settowidth {\xxwidth} {\usebox{\xxcontent}}%
  \settoheight{\xxheight}{\usebox{\xxcontent}}%
  \usebox{\xxcontent}%

  \pdfannot width \xxwidth height \xxheight depth 0pt {%
       /Subtype /RichMedia
       /RichMediaContent  \the\contentnum\space 0 R 
       /RichMediaSettings \the\settingsnum\space 0 R 
}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\flashmoviex{\@ifnextchar[\@flashmoviex{\@flashmoviex[]}}

\def\@flashmoviex[#1]#2{\flashmovieparamsclear \setkeys{flashmovieparams}{#1}{
  \newcount\filespecnum
  \newcount\filespecnumi
  \newcount\filespecnumii
  \newcount\configurationnum
  \newcount\contentnum
  \newcount\settingsnum

  \flashmovieembedfile{#2}
  \filespecnum=\pdflastobj

  \flashmovieembedfile{SkinOverPlaySeekStop.swf}
  \filespecnumi=\pdflastobj

  \flashmovieembedfile{VideoPlayer.swf}
  \filespecnumii=\pdflastobj
  
  \immediate
  \pdfobj
    {<<
      /Instances
        [<<
          /Asset \the\filespecnumii\space 0 R
          /Params 
            << 
               /Binding /Foreground
               /FlashVars (source=#2&skin=SkinOverPlaySeekStop.swf&skinAutoHide=true&skinBackgroundColor=0x00FF00&skinBackgroundAlpha=0.33&volume=1.00)
            >>
        >>]
      /Subtype /Flash
    >>}
  \configurationnum=\pdflastobj

  \immediate
  \pdfobj
    {<<
      /Assets << /Names [(#2) \the\filespecnum\space 0 R (skinover.swf) \the\filespecnumi\space 0 R (VideoPlayer.swf) \the\filespecnumii\space 0 R] >>
      /Configurations [\the\configurationnum\space 0 R]
    >>}
  \contentnum=\pdflastobj

  \immediate
  \pdfobj
    {<<
      /Activation 
        << /Type /RichMediaActivation 
           /Condition /PO 
           /Configuration \the\configurationnum\space 0 R 
           /Animation 
             << /Subtype /Linear 
                /Speed 1 
                /Playcount 1 
             >> 
           /Presentation
             << /PassContextClick false
                /Style /Embedded 
                /Toolbar false
                /NavigationPane false
                /Transparent true
                /Window 
                  << /Type /RichMediaWindow 
                     /Width  << /Default 100 /Min 100 /Max 100 >> 
                     /Height << /Default 100 /Min 100 /Max 100 >> 
                     /Position 
                       << /Type /RichMediaPosition 
                          /HAlign /Near 
                          /VAlign /Near 
                          /HOffset 0 
                          /VOffset 0 
                       >> 
                  >> 
              >> 
        >> 
      /Deactivation 
        << /Type /RichMediaDeactivation 
           /Condition /XD 
        >> 
    >>}
  \settingsnum=\pdflastobj

  \newlength{\xxwidth}
  \newlength{\xxheight}
  \newsavebox{\xxcontent}

  \sbox{\xxcontent} {{\hbox to \flashmoviewidth {\vbox to \flashmovieheight { }}}}

  \settowidth {\xxwidth} {\usebox{\xxcontent}}%
  \settoheight{\xxheight}{\usebox{\xxcontent}}%
  \usebox{\xxcontent}%

  \pdfannot width \xxwidth height \xxheight depth 0pt {%
       /Subtype /RichMedia
       /RichMediaContent  \the\contentnum\space 0 R 
       /RichMediaSettings \the\settingsnum\space 0 R 
}}}