45

Some time ago I asked this question How to include a movie in a PDF? Step by step instructions. (I tried everything documented there, and links therein. I can't find the combination of tools to be able to playback embedded movies in a PDF viewer in Linux.)

This time I am going to be more direct: Was anyone, with a certain combination of tools and viewer, able to create a PDF from TeX with an embedded movie and play it back in a Linux viewer (for example some version of Acrobat)?

If, so what package, tex version, acrobat version was used?


EDIT 2014

Thanks to @AlexG, great advances have been made regarding the inclusion of movies and in particular the playback in Linux. It is just a pity that Acrobat for Linux is at its end of life (not so much for Adobe but because nobody is picking up the torch for embedded media).

This edit simply summarizes a working solution that is illustrated by defining a command \includemove[dimensions]{moviewithoutextension}, that produces movies that can be played back in Acrobat 9.4.1 (Linux), Acrobat for Windows and Mac and that fallbacks to external players (and a still picture) in other PDF viewers.

Assumptions:

  1. You have a copy of jw-player 5.10 (not 5.9 or 6.x) in your local directory and it is named player.swf. (from here http://developer.longtailvideo.com/trac/browser/tags/mediaplayer-5.10, documentation here: http://www.longtailvideo.com/support/jw5/31138/configuration-options)
  2. You have ffmpeg version 2.1.4.
  3. You have a copy of your movie in the mp4 format. Any movie can be converted in this way

    ffmpeg -i $MYMOVIE.vid -vf scale="trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -profile:v high -pix_fmt yuv420p -g 25 -r 25 $MYMOVIE.mp4

    ffmpeg -i $MYMOVIE.vid -qscale 0 -vcodec libx264 -x264opts keyint=25 $MYMOVE.mp4

  4. A preview image with the same name but extension png. This can be achieved by converting your movie in this way and taking an snapshot:

    ffmpeg -i $MYMOVIE.mp4 -ss 00:00:2.1 -f image2 -vframes 1 $MYMOVIE.png

  5. [optional] A PDF image with the same name but pdf extension to replace the PNG preview in case Flash content is not active.

  6. You are OK using the packages hyperref (and media9 of course).

  7. [for playback] You have Acrobat 9.4.1 (for playback in Linux) or more modern versions in other systems.

  8. [for playback] For other PDF viewers: the extension mp4 is associated with some application and the movie is distributed with the PDF.

Limitations (of my poor implementation, not of media9)

  1. Only width and/or height can be specified as options.
  2. No other player than jw-player can be used (options are hardcoded in the command definition).
  3. It assumes a lot of defaults regarding the behavior of the embedded player.
  4. [For fallback] The definition tries it best to have a nice fallback mode for other viewers, and you have to choose (see the code) between embedding the movie or having an external file.
  5. [For playback] I don't know if it works in all viewers, it works at least in Acrobat 9.4.1 (Linux) and Evince 3.10.3 (Linux). I saw it work in Acrobat X in Windows and Mac after a "security message" confirmation.

Given this conditions, the following document that includes the definition of \includemovie and summarizes a working solution.

\documentclass{article}
\usepackage[noplaybutton]{media9}
\usepackage[colorlinks]{hyperref}
\usepackage{attachfile2}

\newcommand{\includemovie}[2][]{
    \includemedia[
        #1,
        activate=pageopen,transparent,
        addresource=#2.mp4,addresource=#2.png,
        flashvars={
            file=#2.mp4&image=#2.png&
            stretching=uniform&start=0&
            screencolor=white& %improves render in light backgrounds
            controlbar.position=over&controlbar.idlehide=true&
            autostart=true&repeat=always&smoothing=true
            %&bufferlength=10 % may improve repetition of short videos
        }
    ]{ % for disabled content (in most cases this is fallback)
        \begin{tabular}{ll}
            \mbox{
            %   \href{run:#2.mp4} % for not embedded fallback
                \textattachfile[color={0 0 0}]{#2.mp4} % for embedded fallback
                {\texttt{|\kern-.23em>}} % poor play button
            } & \raisebox{-\height}{\includegraphics[#1]{#2}}
        \end{tabular}
    }{player.swf}
}

\begin{document}

\includemovie[width=5cm]{MYMOVIE} %no extension!

\end{document}

(note: you may benefit by producing JPEG snapshots, PNG are usually very big, sometimes as big as the whole movie)

alfC
  • 14,350
  • The ffmpeg command line to produce a usable video file, item (3), may need to be adjusted. See http://tex.stackexchange.com/a/141765. – AlexG Apr 15 '15 at 11:09
  • At least -profile:v high -pix_fmt yuv420p should be added to the ffmpeg command line to get a usable MP4 video file (item 3 of your list). – AlexG May 20 '15 at 07:58
  • Thanks, my ffmpeg is complaining that qscale is ambiguous. Do you have a complete line to suggest? (feel free to edit). BTW, I never had problems using this command line (in spite of not understanding some of the options). – alfC May 20 '15 at 08:01
  • See the link in my first comment. It also adds an option to ensure even pixel numbers in both video dimensions. Recent libx264versions seem to use a different profile/pix format which is not compatible with Flash Player. – AlexG May 20 '15 at 08:05

4 Answers4

20

Update Thanks to @percusse for pointing out in his comment that the original answer was not the one the OP was asking for.

So I did a little searching and found this link. Basically, the workaround is,

  1. Install Adobe Reader 9.4.1.
  2. Install flashmovie or copy it to your source folder (especially the player_flv_maxi.swf)
  3. Write \includepackage{hyperref} and \includepackage{flashmovie} in your preamble. A minimal working environment would be:

    \documentclass{article}
    
    \includepackage{hyperref}
    \incldepackage{flashmovie}
    
    \begin{document}
    
    \flashmovie[width=12cm,height=8cm,engine=flv-player,auto=1]{movie.flv}
    
    \end{document}
    

It seems that, in Linux, you can only get embedded videos in Acrobat with Acrobat version 9.4.1. (Why this is, I don't know yet.) You will also need to install ffmpeg to convert your videos to flv

I downloaded the sample text-flv.tex file from the link. How flashmovie works is summarized in this file.

I can verify the claim of that the movie cannot play on the output pdf on my Adobe Reader with version 9.4.7. Opening the pdf gives a message A 3d data parsing error has ocurred. I can also verify that it works like a charm in Adobe Reader 9.4.1.

BTW, I have TeX version 3.1415926-2.4-1.40.13.

Update: If you are not after embeding First, make sure that you have installed all required packages to run your movie format. You will need to load the package movie15, which comes with TeXLive 2012. The manual says that this package is already obsolete and that you should consider using movie9 instead, which is in ctan but not in TeXLive2012. I used movie15 in this answer.

Try the following MWE:

\documentclass{article}

\usepackage{hyperref}
\usepackage{movie15}

\begin{document}

    \begin{figure}[ht]
    \includemovie[poster,text={\small(Loading Video...)}]{3cm}{2cm}{movie.mp4}
    \end{figure}

\end{document}

The poster option inserts the first frame of the movie. The text option appears before the movie is loaded into your pdf viewer. 3cm and 2cm are the width and height of the frame and movie.mp4 is the name of your movie.

Run pdflatex movie.tex where movie.tex is your tex file. I am using Ubuntu 12.04 and I use evince 3.4 to view the pdf. Just type evince movie.pdf in your terminal. Click on the frame to play the movie. The movie will open with your default movie viewer.

I haven't tried movie9 though.

Update This is in response to User 17791. My previous comment to his answer was deleted when the question was edited by moderator. Here it is, @User17791:

pdfTeX 3.1415926-2.4-1.40.13 (TeX Live 2012)
kpathsea version 6.1.0
Copyright 2012 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.5.10; using libpng 1.5.10
Compiled with zlib 1.2.7; using zlib 1.2.7
Compiled with xpdf version 3.03

Below are two snapshots of my desktop with a movie being played in Acrobat 9.4.1. (It's a video of a ritual dance here in Baguio City.)

enter image description here

enter image description here

hpesoj626
  • 17,282
  • 2
    This is nice but OP specifically asks for embedded playback. – percusse Aug 18 '12 at 07:26
  • 1
    hpesoj626, could you please post the output of pdflatex -v ? So I can compare the libraries it is compiled against, and I am able to figure out why AR crashes,even following all your steps. Thanks in advance! –  Aug 20 '12 at 02:38
  • 1
    Thanks hpesoj626 for your detailed answers. I have succeeded in getting a beamer+flashmovie+AR 9.4.1 to work, creating an avi movie from jpg images using mencoder, and converting the avi movie to mp4 with ffmpeg. My distro was Fedora 16 When I say to work, I mean I was able to put AR in presentation mode, and clicking on the image, the movie played. I was able to pause the movie also. BUT: Unfortunately, I have some days ago upgraded to Fedora 17. Repeating all the steps, I am able to see the movie in presentation mode, but when I want to change to the next slide, AR crashes. So, now I am comp –  Aug 19 '12 at 17:48
  • @Fiz65, I am sorry but I have never even tried using Fedora. Did you still have the same settings for AR and your TeX though? – hpesoj626 Aug 23 '12 at 03:53
  • Thanks, I think you hit the nail on the head: Acrobat Reader 9.4.1 and flashmovie is the only combination in which I was successful in embedding (displaying) movies in PDF, and only with the default players (not the fancy ones). I did not succeed using movie15 or media9 yet. Also I can confirm some crashes when changing pages that Fiz65 reported. – alfC Sep 09 '12 at 09:26
  • @alfC Personally, I prefer using portable VLC for my video presentations. As with Acrobat, I don't use it that much too. But that's just me. – hpesoj626 Sep 09 '12 at 10:07
  • The only reason to use Acrobat is the embedded movies. An idea solution would be to embed the movie when possible and otherwise (other version of Acrobat or other viewers) fallback to normal attachment/external link. – alfC Sep 09 '12 at 17:43
  • @alfC: Upto 9.4.1 Adobe Reader for Linux had the FlashPlayer built-in. Afterwards it was removed by Adobe. The version of the last built-in Player was 9.x. Therefore it could not render newer SWF content, such as the media players that ship with media9 and which require Flash-10.x player. If you want to use media9 with AdobeReader-9.4.1, try the player_flv_maxi.swf that flashmovie is using, instead of VPlayer.swf. It is FlashPlayer-9.x compatible, but only plays FLV video, not MP4+h.264. – AlexG Sep 10 '12 at 10:27
  • @alfC: I must correct myself. Even MP4+h.264 plays in player_flv_maxi.swf in AR-9.4.1. – AlexG Sep 10 '12 at 13:16
  • @hpesoj626, it takes some coding but with media9 (see the other answer, by AlexG) one can have the best of both worlds. Because there is alternative code that the viewer will interpret if the flash code cannot be rendered. – alfC Mar 18 '14 at 15:50
  • evince worked fine for me. Okular worked in one of my laptops but it did not in the other. Any hint about why ocular would not work? – Herman Jaramillo Sep 11 '18 at 14:28
15

Update

As of 2013/11/04, package media9 contains media player Flash components VPlayer9.swf and APlayer9.swf. They are compatible with the (somewhat outdated) Flash Player 9 plugin that is bundled with Adobe Reader for Linux 9.4.1 and can be used for producing PDF documents with embedded video (MP4/H.264) and audio (MP3) which target this particular Linux version of Adobe Reader.

Alternatively, any Flash-based media player found on the Web which is Flash-9 compatible and which can be configured via FlashVars could be used. (Though the number of such players should be decreasing with the advent of newer Flash versions.)

NB: Flash and media playback was dropped in more recent Readers. AR-9.4.1 is the last version on Linux which supports Flash.

Adobe Reader 9.4.1 for Linux can be downloaded from ftp://ftp.adobe.com/pub/adobe/reader/unix/9.x/9.4.1/.

Example code using cube.mp4 and VPlayer9.swf from the media9 package:

\documentclass{article}
\usepackage{media9}[2013/11/04]

\begin{document}

\includemedia[
  width=0.6\linewidth,height=0.6\linewidth,
  activate=pageopen,
  transparent,
  addresource=cube.mp4,
  flashvars={
    source=cube.mp4     % same path as in addresource!
   &loop=true           % loop video
   &scaleMode=letterbox % preserve aspect ratio
  }
]{}{VPlayer9.swf}

\end{document}
AlexG
  • 54,894
  • Do you know how to make includemedia to use the jw-player engine? I understand that media9 is supposed to replace flashmovie, however if I use VPlayer9.swf the video plays with a lot of flicker and autoloop doesn't work well. If use flashmovie with jw-player I don't have this problem. – alfC Feb 18 '14 at 16:26
  • 1
    @alfC: Replace VPlayer9.swf with player_flv_maxi.swf. The Flasvars option should read flashvars={flv=cube.mp4&autoplay=1&loop=1&showplayer=autohide}, with cube.mp4 replaced by the video file of yours, as set by the addresource option. – AlexG Feb 19 '14 at 07:23
  • Finally, player_flv_maxi.swf plays as well as jw-player.swf (from flashmovie) does. \includemedia[width=0.6\linewidth,height=0.5\linewidth, activate=pageopen, transparent, addresource=cube.mp4, flashvars={flv=cube.mp4&autoplay=1&loop=1&showplayer=autohide}]{}{player_flv_maxi.swf}. The only problem (feature!) is that one has to match the width and height of the video to avoid the black box of the player. – alfC Feb 19 '14 at 13:46
  • @alfC: VPlayer offers a number of scaling options one can chose from: letterbox (best fit), none (the way jw-player behaves), stretch (no black margins at all), zoom. Could you make the video file available for download which produces the reported problems in VPlayer? – AlexG Feb 19 '14 at 13:57
  • My last concern (black box proportions) is addressed completely by using a poster image and automatic width or height. – alfC Feb 19 '14 at 14:35
  • @alfC Could you please post the configuration options (FlashVars) you used for automatic width and height setting? – AlexG Feb 19 '14 at 14:44
  • VPlayer9 doesn't work well with Acrobat Linux (9.4.1), specially with autoloop. 2) Unfortunately, I can't make the download available. Let me just say that is quite high resolution (800x800) and plays well with jw-player autoloop (and flashmovie).3) Automatic size is achieved by removing the height/width options and adding poster that is a screenshot of the first frame: \includemedia[activate=pageopen, flashvars={...}}{\includegraphics[width=0.6\linewidth]{cube.png}}{player_flv_maxi.swf} 3) where are the options for player_flv_maxi.swf 4) Can I use jw-player alternatively?
  • – alfC Feb 19 '14 at 16:17
  • player_flv_maxi.swf flashvar options: http://flv-player.net/players/maxi/documentation/ – alfC Feb 19 '14 at 16:29
  • @alfC: Thanks a lot for the information. As for (4), you can use any Flash-based player that is Flash-9 compatible and which can be configured using FlashVars. – AlexG Feb 19 '14 at 16:33
  • ok, I wasn't setting the flashvars for jw-player incorrectly. \includemedia[activate=onclick,addresource=cube.mp4, flashvars={file=cube.mp4} ]{\includegraphics[width=0.6\linewidth]{cube.png}}{jw-player.swf}. I would say though, player_flv_maxi seems to work better. – alfC Feb 19 '14 at 16:48
  • Sorry to bother again. I can't make any of the media9 solutions work better than the flashmovie. I was hoping I could move on to media9 but the playback is always choppy and unstable (in Acrobat 9.4.1, the only one I can use), the switch otherwise makes sense because media9 is more powerful. Perhaps you can tell me exactly what is the media9 code (and options) to replace this flashmovie code: \flashmovie[auto=1,loop=1,controlbar=1,engine=jw-player,width=7.6cm,height=5.2cm,image=cube.png]{cube.mp4} which works perfect©. – alfC Mar 17 '14 at 11:27
  • @alfC Could you send me a link where to download jw-player? Btw, I am still working on the playbutton look. – AlexG Mar 17 '14 at 11:41
  • Good question, I don't know where I got it from, I don't even know if flashmovie is using the same version I have in the directory (because it works even if remove it locally) [that could be the reason of the different between flashmovie and media9]. I downloaded it again from here http://www.jwplayer.com/sign-up/ but it is a much newer version (162436 bytes vs. 113505 bytes). – alfC Mar 17 '14 at 11:59
  • I am afraid this new version is not flashplayer-9 compatible which is mandatory for ar-9.4.1, isn't it? – AlexG Mar 17 '14 at 12:02
  • ok, disregard last comment. I found all the old versions here: http://developer.longtailvideo.com/trac/browser/tags . Where can I find the jw-player that flashmovie uses in my computer then? – alfC Mar 17 '14 at 12:03
  • For the record: \includemedia[width=0.49\linewidth,height=0.3\linewidth,activate=pageopen,addresource=cube.mp4,flashvars={file=cube.mp4&screencolor=white&image=cube.png&autostart=true&repeat=always}]{\includegraphics[width=0.3\linewidth]{cube}}{player.swf} – alfC Mar 17 '14 at 13:12
  • @alfC. player.swf is configured to use cube.png. Therefore it must be embedded into the PDF as a resource: ...,addresource=cube.png,.... – AlexG Mar 18 '14 at 11:44
  • that explains why I see garbage before the movie runs. And why I didn't see it with flashmovie. Can you add something like the simple flashmovie commnand to media9 in which not so much redundant information is needed? (I know the flashvar options will depend on the engine but these can hard coded for each engine= options. I'll try to write a newcommand as a first attempt. Also, did you figure out which version of player.swf I was using? It really has no match in terms in compatibility of Linux Acrobat 9.4.1. – alfC Mar 18 '14 at 15:37
  • I found the exact player that work very well for me with Acrobat 4.9.1 here: http://developer.longtailvideo.com/trac/browser/tags/mediaplayer-5.10 . Of the jw-player family this is one of the few players that work with Acrobat 4.9.1, version 4 or 6 don't work. – alfC Mar 19 '14 at 01:23
  • By playing with jw-player I determined that the main problem with other viewers at playing a repeated short video is the bufferlength. Unfortunately I don't see such option in VPlayer[9].swf, not at least documented here: https://developers.google.com/youtube/player_parameters?csw=1 – alfC Mar 19 '14 at 02:49
  • I created an includemovie command in my edit to the question to summarize this discussion. – alfC Mar 20 '14 at 16:37
  • @alfC: Thank you for providing the wrapper macro. It is certainly useful for other users. Nevertheless, I prefer not to add such a wrapper because it would be player-specific. I want to keep the generic interface for embedding Flash. – AlexG Mar 20 '14 at 23:01
  • I understand, no argument about that. I had to do it to make it practical to use, specially for the fallback and other mostly redundant information. One thing I noticed is that flashvars for the players and options I tried do not interfere with each other, options not understood by a player are ignored. They can be passed independently of the player specification. So, it seems that a convenience command like this is quite flexible and general \includemovie[DimensionSpec]{PlayerSWF}[flashvars]{MovieFile}[PictureFile]. – alfC Mar 20 '14 at 23:41
  • Is it possible to make attachfile2 to reuse a file included as addresource or viseversa? The idea is to avoid attaching the file twice. – alfC Apr 06 '14 at 18:16
  • @alfC. In principal, yes. I will be looking into it. The problem is that several media and auxiliary files as well as the media player itself may belong to one RichMedia inclusion, which renders a single clickable area useless. But the files could appear in the file-attachment pane of the viewer. – AlexG Apr 07 '14 at 07:18
  • A possible route: http://tex.stackexchange.com/questions/19117/attach-displayed-image-to-the-pdf-without-storing-it-twice . (In my summary of the solution, the clickable attachment is behind the movie so it is visible (and clickable if the movie/rich media) doesn't show up.) – alfC Apr 07 '14 at 20:55
  • 1
    @alfC: The feature you are looking for was implemented in the movie15 package, were a file attachment annotation was placed behind the Screen annotation and which was accessible in PDF viewers that did not support the Screen annot. There is, however, a problem with the RichMedia annotation (used by media9): In the non-activated state, AR always renders it behind any other annotation of different type (Link, FileAttachment, ...), even if it is inserted a-posteriori by LaTeX. – AlexG Apr 08 '14 at 09:27
  • 1
    @alfC: (Cont'd) Therefore, you cannot activate a RichMedia by click in AR if there is another annotation at the same place on the page. Thus, only the file attachments pane in the Reader GUI is usable for opening the media file or downloading it from the PDF. – AlexG Apr 08 '14 at 09:27
  • Yes, that is why in my solution I had to put the "play button" (really "|>") to a side. Still I think this is a detail with respect to the feature of having access to the media through normal PDF attachments. no? Thanks for your ongoing effort on media9! – alfC Apr 08 '14 at 22:41
  • still the activated areas seems to be a minor detail one can put the link to the side of the image. Is possible to attach the resource both as embedded/attached2 file and as flash resource without duplicating the data? – alfC Apr 22 '14 at 09:52
  • 1
    @alfC Just uploaded a new version (0.44) to CTAN. It provides package and command option attachfiles. Media and player files can be opened or downloaded from the PDF via the File Attachments Pane of AR. – AlexG Jun 04 '14 at 07:36