% media9nf-doc.tex: user manual for the media9nf package
%
% Copyright (C) 2026 Gonçalo Pena
% This file is part of the media9nf package and may be distributed and/or
% modified under the conditions of the LaTeX Project Public License, version
% 1.3c or (at your option) any later version.
%
% Compile with pdflatex (twice).
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=2.5cm]{geometry}
\usepackage{graphicx}
\usepackage{media9nf}
\usepackage{fancyvrb}
\usepackage[hidelinks]{hyperref}

\newcommand\pkg[1]{\textsf{#1}}
\newcommand\opt[1]{\texttt{#1}}
\newcommand\cs[1]{\texttt{\textbackslash#1}}
\newenvironment{optlist}
  {\begin{description}\setlength\itemsep{2pt}}
  {\end{description}}

\title{The \pkg{media9nf} package\\[4pt]
  \large Video and audio in PDF with the \pkg{media9} interface, without Flash}
\author{Gonçalo Pena\\\url{https://github.com/gpena/media9nf}}
\date{Version 0.2.0, 2026/12/04}

\begin{document}
\maketitle

\section{Introduction}

\pkg{media9} by Alexander Grahn is the usual way to put video and sound in a
PDF made with \LaTeX. It plays them through Flash players (\texttt{VPlayer.swf},
\texttt{APlayer.swf}) stored in the PDF. Adobe ended Flash in December 2020, and
current Acrobat and Acrobat Reader no longer play Flash content, so videos made
this way show only their poster.

\pkg{media9nf} keeps the \pkg{media9} commands (\cs{includemedia},
\cs{addmediapath} and \cs{mediabutton}) and most of their options. It embeds the
media file itself in a RichMedia annotation of subtype \texttt{Video} or
\texttt{Sound}, and the PDF viewer plays it with its own player. Like
\pkg{media9}, it uses \pkg{pdfbase} for the low-level PDF work.

\pkg{media9nf} is a separate package. It is not maintained by the author of
\pkg{media9}, and it cannot be loaded together with \pkg{media9}.

\section{Example}

The video below is embedded in this PDF. Click it to start playback in a viewer
that supports RichMedia (see section~\ref{sec:viewers}). Other viewers show the
poster image only.

\begin{center}
  \includemedia[
    width=0.6\linewidth,
    activate=onclick,
    deactivate=pageinvisible
  ]{\includegraphics{media9nf-poster.png}}{media9nf-sample.mp4}
\end{center}

It was produced by
\begin{Verbatim}[frame=single]
\usepackage{graphicx}
\usepackage{media9nf}
...
\includemedia[
  width=0.6\linewidth,
  activate=onclick,
  deactivate=pageinvisible
]{\includegraphics{media9nf-poster.png}}{media9nf-sample.mp4}
\end{Verbatim}

\section{Requirements and drivers}

\pkg{media9nf} needs a \LaTeX{} format from 2023-11-01 or later and the
\pkg{pdfbase} package, which is distributed with \pkg{media9}. It works with
\begin{itemize}
  \item pdf\LaTeX{} and Lua\LaTeX;
  \item Xe\LaTeX{};
  \item \LaTeX{} followed by \texttt{dvipdfmx} (load the package with the
    \opt{dvipdfmx} option);
  \item \LaTeX{} followed by \texttt{dvips} and Ghostscript
    (\texttt{ps2pdf -dNOSAFER}). Graphics in the poster must then be in EPS
    format.
\end{itemize}

Option \opt{bigfiles} is on by default, so large media files do not exhaust
\TeX's memory. Turn it off with \opt{bigfiles=false} only if you have a reason
to.

Each embedded file gets its MIME type (e.g.\ \texttt{video/mp4}) and size. With
pdf\LaTeX, files in formats that are already compressed (MP4, MOV, WebM, MP3,
AAC, Ogg and similar) are stored without Flate compression, which saves
compile time and makes almost no difference to the file size. The other
engines and drivers compress them as usual.

\section{Commands}

\subsection{\cs{includemedia}}

\begin{Verbatim}
\includemedia[<options>]{<poster>}{<media file>}
\end{Verbatim}

\noindent\texttt{<poster>} is any \LaTeX{} material, usually
\cs{includegraphics}. It sets the size of the annotation and is shown until the
media is activated. \texttt{<media file>} is the file to embed. Files ending in
\texttt{.mp3}, \texttt{.wav}, \texttt{.ogg} and \texttt{.aac} are embedded as
sound (unless \opt{audioasvideo} is set) and everything else as video. H.264/AAC in an MP4 container plays in the
most viewers.

A URL (\texttt{http://}, \texttt{https://}, \ldots) can be given instead of a
local file. The media is then streamed and not embedded.

\subsection{\cs{addmediapath}}

\begin{Verbatim}
\addmediapath{<directory>}
\end{Verbatim}

\noindent Adds a directory to the list searched for media files.

\subsection{\cs{mediabutton}}

\begin{Verbatim}
\mediabutton[<options>]{<normal appearance>}
\end{Verbatim}

\noindent Makes a push button that acts on a media annotation, identified by
the \opt{label} given to \cs{includemedia}. Buttons need JavaScript, so they
work in Adobe viewers only.

\section{Options}

Options for \cs{includemedia} can also be given as package options; they then
apply to every \cs{includemedia} in the document. \opt{label},
\opt{addresource} and \opt{flashvars} are accepted by \cs{includemedia} only.

\subsection{Package and \cs{includemedia} options}

\begin{optlist}
  \item[\opt{width=}, \opt{height=}, \opt{totalheight=}] Resize the annotation
    to the given size. Without any of them the natural size of the poster is
    used.
  \item[\opt{keepaspectratio}] Keep the aspect ratio of the poster when both
    a width and a height are given. On by default.
  \item[\opt{scale=}] Scale the annotation by a factor.
  \item[\opt{activate=pageopen|pagevisible|onclick}] When the media is
    activated. Default \opt{onclick}.
  \item[\opt{deactivate=pageclose|pageinvisible|onclick}] When it is
    deactivated. Default \opt{pageinvisible}.
  \item[\opt{windowed=<width>x<height>@<position>}] Play in a floating window
    instead of on the page. \texttt{<position>} is one of \opt{tl}, \opt{tc},
    \opt{tr}, \opt{cl}, \opt{cc}, \opt{cr}, \opt{bl}, \opt{bc}, \opt{br}.
    Both parts are optional, e.g.\ \opt{windowed=640x360} or
    \opt{windowed=@br}. \opt{windowed=false} switches it off.
  \item[\opt{transparent}] Let the page show through transparent parts of the
    player.
  \item[\opt{passcontext}] Pass right clicks to the player instead of the
    viewer.
  \item[\opt{draft}, \opt{final}] In draft mode only the poster is typeset and
    nothing is embedded.
  \item[\opt{attachfiles}] Also attach the media files to the PDF, so readers
    can save them from the attachments panel.
  \item[\opt{audioasvideo}] Embed audio files as video, so that Okular plays
    them (see section~\ref{sec:viewers}). Off by default. Not tested in Adobe
    viewers.
  \item[\opt{label=}] Name the annotation so that \cs{mediabutton} can refer to
    it.
  \item[\opt{addresource=}] Embed an additional file. May be repeated.
  \item[\opt{flashvars=}] Passed unchanged to the viewer's player. Usually not
    needed.
  \item[\opt{playbutton}, \opt{noplaybutton}] Accepted for compatibility with
    \pkg{media9}. They have no effect.
\end{optlist}

\noindent Driver options: \opt{pdftex}, \opt{luatex}, \opt{xetex},
\opt{dvips}, \opt{dvipdfmx}. Package-only option: \opt{bigfiles}.

\subsection{\cs{mediabutton} options}

\begin{optlist}
  \item[\opt{mediacommand=<label>}] Activate the annotation called
    \texttt{<label>}. May be repeated.
  \item[\opt{jsaction=<label>:<JavaScript>}] Run JavaScript when the button
    is pressed.
  \item[\opt{overbg=}, \opt{overfg=}] Appearance when the mouse is over the
    button, and while it is pressed.
  \item[\opt{tooltip=}] Text shown when the mouse is over the button.
  \item[\opt{draft}, \opt{final}] As for \cs{includemedia}.
\end{optlist}

\section{Converting \pkg{media9} documents}
\label{sec:convert}

Replace \verb|\usepackage{media9}| with \verb|\usepackage{media9nf}|. Most
documents then compile unchanged.

When the media file argument is a Flash player, \pkg{media9nf} drops the player
and embeds the media it would have played. The media file is taken from
\opt{flashvars} (\texttt{source=\ldots}) or else from the first
\opt{addresource} that is not a \texttt{.swf} file. So
\begin{Verbatim}
\includemedia[
  addresource=talk.mp4,
  flashvars={source=talk.mp4&autoPlay=true}
]{\includegraphics{poster}}{VPlayer.swf}
\end{Verbatim}
embeds \texttt{talk.mp4} directly and writes a warning to the log.

\pkg{media9} \cs{mediabutton} actions of the form
\opt{mediacommand=<label>:<command>} call ActionScript functions in the Flash
player, such as \texttt{playPause} or \texttt{seek}. These have no equivalent
without Flash. \pkg{media9nf} ignores the command part, activates the
annotation instead, and writes a warning.

Flash animations (\texttt{.swf} files other than the media9 players), 3D content
and slideshows are not supported.

\section{Viewer support}
\label{sec:viewers}

Playback depends on the PDF viewer. RichMedia annotations are supported by
Adobe Acrobat and Acrobat Reader and by KDE Okular. Okular plays video but not
sound: it ignores annotations whose instance type is \texttt{Sound}, which is
what \pkg{media9nf} writes for \texttt{.mp3}, \texttt{.wav}, \texttt{.ogg} and
\texttt{.aac} files. Option \opt{audioasvideo} writes audio as \texttt{Video}
instead, which Okular plays; how Adobe viewers handle that is untested. Browser
PDF viewers, macOS Preview and SumatraPDF show the
poster but do not play the media. Test your PDF in the viewer your readers will
use.

\section{License}

Copyright \copyright{} 2026 Gonçalo Pena.

This work may be distributed and/or modified under the conditions of the
\LaTeX{} Project Public License, either version 1.3c of this license or (at
your option) any later version. The latest version of this license is at
\url{https://www.latex-project.org/lppl.txt}. This work has the LPPL
maintenance status `maintained'; the Current Maintainer is Gonçalo Pena.

The interface follows the \pkg{media9} package by Alexander Grahn.

\end{document}
