3

I may be beating a dead horse here; but I hope I'll be forgiven, as I have at least a Latex MWE, and some notes about packages :). The thing is this: for a long time I've been looking for some sort of a platform, where I could write a text script, for what would eventually become a video edit (Command-line video editing in Linux (cut, join and preview) - Super User); and I think Latex/PDF has the potential.

Unlike in Adjusting the framerate with the animate package [closed], however, I wouldn't intend to use Adobe Reader as a viewer/player. Instead, I'm interested in, basically, considering the Latex or PDF format as a "container" for a timed presentation, which includes videos - and what I'd need is a script or program which would "parse" the container, and eventually generate an image sequence at a predetermined frames-per-second rate. This is maybe best discussed through an example; so with the below MWE - which uses beamer, animate and media9 - and screen capturing the Adobe Reader full-screen performance, I obtain this animated .gif (a longer MWE with comments is on https://gist.github.com/anonymous/e6b7051cf270594d2b38, along with a full-size video on https://vid.me/QZrL (from where you can also download a .mp4 version, JavaScript required)):

              test-presentation.gif

I think it is clear that Adobe Reader cannot be expected to hold a video-tight frame rate (especially since e.g. {animation} uses JavaScript timers inside the PDF to do the animating; and especially not in older Linuces like Ubuntu 11.04, where I did the screen capture). That is why I'd hope for a tool, which would preserve these attributes of the video above:

  • Slide (frame) duration
  • Transition effect and duration
  • Animations
  • Frame-accurate display of embedded videos.

With this, I could export a "base video" which I could load in a video editor; and then possibly overlay the original embedded videos over that in the editor, and then export a "final video". Firstly, I would imagine a tool that would parse the PDF, and export an image sequence like in this shell pseudocode:

mockPdfRender --framerate 24 --in test.pdf --out imgseq/%05d.png

However, that tool would need to "know" that from e.g. this 5-page PDF should be rendered into 1.5+1.5+2.5+5.5+1.5 = 12.5 seconds; @ 24 fps = 300 images; and since many of these facilities depend on embedded JavaScript, I'd imagine it would be hard. On the other hand, maybe it would be more possible, if a change was implemented in {beamer}, {animate} and {media9}, such that I could write a directive in my Latex file:

\documentclass{beamer}
\mockPfdRender[framerate=24]{} % the directive
\usepackage{media9}
\usepackage{animate}
...

... which, when encountered, would instruct Latex to export a PDF, not with 5 pages, but with 300 pages, each containing a frame of the animation. On such a PDF, I could simply use ImageMagick's convert:

convert -density 100 test.pdf test-%05d.png

... to generate a .png image from each page of that PDF; giving me a frame-accurate image sequence that I could then import into a video editor (or ffmpeg), and generate a video out of it.

So, formally, my question would be: is there a facility allowing something like this in the Latex packages? If not, would it be at all possible to implement - so it works on the MWE (i.e., across beamer, animate and media9)? Also, some subquestions:

  • How can I understand the positioning of animation and media on {beamer} slides?
  • In {media9}, is there a way to start a video at a given time, and stop it a later time, automatically when the slide (page) with the video is opened?
  • In Inject JavaScript with pdflatex etc. for page level events, \pdfpageattr{/AA << /O << /S/JavaScript ... is used to set up a JS listener when all/any page of the PDF is opened; is there a way to limit that to a single page (apart from writing a JS if(..){..} clause)
  • Is there any way to make {media9} work with annotRM.callAs() JS command (see below)?

Aside from that, here are some notes re: the MWE on my platform:

  • As per Did anyone succeed in playing embedded movies inside Acrobat in Linux?, I had to use Adobe Reader 9.4.1 to play video in PDF; apparently that version included an embedded Flash Player 9, which was subsequently removed (and later acroreads apparently require a standalone Flash Player to be installed on the system)
  • \movie from package {multimedia} didn't work at all; had to use \includemedia from {media9}
  • with \includemedia, using VPlayer.swf didn't work at all; had to use VPlayer9.swf (apparently because of the embedded Flash Player 9)
  • \includemedia movie with sound caused acroread 9.4.1 to freeze (waiting for pthread_join()) upon exiting the slide, unless I had specified my default card in ALSA's ~/.asoundrc:

    pcm.!default {
      type hw   #must have type
      card 0    #must have, else "card is not defined"
    }
    

    With this spec, acroread will survive one entry and exit in the slide playing the video, but will freeze upon second return to the slide and playback of video. Upon freeze, graceful shutdown of acroread is impossible, killall -9 acroread is required

  • Only {beamer}'s \transdissolve worked as a transition inside acroread 9.4.1; others like \transsplitverticalout or \transwipe didn't
  • callAS JS commands addressing {media9} videos (like annotRM['myvideo'].callAS('play')) fail silently in acroread 9.4.1 - and break all subsequent JS commands in that handler; because of that, {hyperref}'s \PushButton can not be used to target videos
  • The only thing that can target a {media9}'s \includemedia video, is {media9}'s \mediabutton with [mediacommand=myvideo:seek [(32.1)],] argument - this doesn't just include JavaScript, it includes actual PDF literals like /CMD << /C (seek) /A [(32.1)] >> /S /RichMediaExecute
  • However, \mediabutton does not render in acroread 9.4.1 in full-screen mode (see my screen capture above, where I click an empty space next to the "Test" button to seek in the video)

Other references:

Well, that was it - here is the MWE:

\documentclass{beamer}
% \usepackage{multimedia} % \movie
\usepackage{media9}[2013/11/04] % ‘media9’ package replaces the now obsolete ‘movie15’ package.
\usepackage{tikz}
\usepackage{animate}

% make as "plain Latex" style/theme for Beamer as possible

\usetheme{default}                      % empty
\usefonttheme{serif}                    % computer modern font
\setbeamercolor{structure}{fg=black}    % reset colors
\setbeamertemplate{navigation symbols}{}%remove navigation symbols

% centered frame title
\setbeamerfont{frametitle}{size=\large,series=\bfseries}
\setbeamertemplate{frametitle}{ % changes all \frametitle
  \begin{centering}
  \insertframetitle
  \par
  \end{centering}
}

\def\choicetransition{\transdissolve[duration=0.5]}

\begin{document}

\title{Testing a timed presentation, with animation and video}
\author{My Author}
\date{2015}

% slide 01
\frame{ \choicetransition \transduration{1.5} %
\titlepage %
}

  % this executes on opening all subsequent pages; but...
  \pdfpageattr\expandafter{\the\pdfpageattr /AA <<
    /O << /S/JavaScript /JS (
    if (this.pageNum==3) {
      ret = annotRM['myvideo'].callAS('play'); % ... does not work
    }
  ) >>
  >>}

% slide 02
\begin{frame}[plain] \choicetransition \transduration{1.5} %
  \begin{center}%
  \Large
  Hello there\\[1em]

  Just trying a plain old frame out
  \end{center}%
\end{frame}

% slide 03: animation
\begin{frame} \choicetransition \transduration{2.5} %
  \frametitle{Testing an animation}
  % last argument of animateinline is frame rate
  \begin{animateinline}[controls=false,autoplay,loop=false]{4}
  \multiframe{8}{n=-0.4+0.1}{
    \begin{tikzpicture}[scale=10,rotate=90]
      \draw[blue,opacity=0.5] (-.1,-.2) rectangle (.4,0.2);
      \draw[red] (-.1,-.2) -- (-.3,\n);
    \end{tikzpicture}
  }
  \end{animateinline}
\end{frame}

% slide 04: video
% wget http://archive.org/download/Elephants_Dream_teaser_2/elephantsdream_teaser.ogv
% ffmpeg -i elephantsdream_teaser.ogv -acodec pcm_s16le -r 24 -g 24 elephantsdream_teaser.flv % Format: Flash Video, Video: Sorenson Spark, Audio: PCM

\begin{frame} \choicetransition \transduration{5.5} %
  \frametitle{Testing a video}

  %\movie[width=3cm,height=2cm,poster,autostart,start=5s,duration=2s,once]{}{elephantsdream_teaser.flv} % nowork, even w/ acroread 9.4.1 {multimedia}
  \includemedia[            % {media9}
    label=myvideo,          % defines JavaScript object annotRM['myvideo']
    width=0.6\linewidth,height=0.6\linewidth,
    activate=pagevisible,
    deactivate=pageinvisible,
    transparent,
    addresource=elephantsdream_teaser.flv,
    flashvars={
      source=elephantsdream_teaser.flv % same path as in addresource!
      &autoPlay=true %
      &loop=false          % loop video
      &scaleMode=letterbox % preserve aspect ratio
    }
  ]{}{VPlayer9.swf} %VPlayer.swf doesn't show video at all! Not even a frame - just white background!
  \PushButton[  %requires package ‘hyperref’
    name=thibut,
    onclick={
      console.show();
      console.println('-------------');
      console.println(annotRM.myvideo);
      console.println(annotRM['myvideo']); % object AnnotRichMedia
    },
    format={  % thought it runs at start, but it doesn't
      console.show();
      console.println('-------------');
    },
  ]{\fbox{Test}}
  \mediabutton[%
    mediacommand=myvideo:seek [(32.1)],% ok
    %jsaction=myvideo:{app.alert("Test " + typeof(annotRM['myvideo']));} % works, prints 'object'
  ]{\color{blue}\fbox{SEEK}} % works, but is invisible in acroread 9.4.1 (and visible in evince?)?
\end{frame}

% slide 05: end

\begin{frame}[plain] \choicetransition \transduration{1.5} %
  \begin{center}%
  \LARGE
  Fin
  \end{center}%
\end{frame}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.