# Videos for scientific presentations

Videos provide a great way to display rather large and complex set of data in a clear and concise fashion. However, video encoding and embedding is generally a painful process for most of the scientific community when in a hurry before a conference. The vast array of codecs, container file types and hazardous symbolic links in files are probably to blame for this. Tackling such issues is however not impossible, and may increase your video quality and your compression ratio, while maintaining compatibility with the two slideshow softwares I use (Microsoft Powerpoint ® and Adobe Reader CC ®).

### Encode a video from a set of images

ImageJ and MATLAB natively provide solutions to create movie files, respectively from image stacks and movie objects (based on a figure). Unfortunately, customization options are scarce and output quality is often not up to our (my) expectations. Worse, the output file size is not always reasonable.

A free, multi-platform, command line austere alternative is called ffmpeg. One of the many features of ffmpeg compiles an image sequence into a video file using efficient codecs. It also provides tools to re-encode your video files if their exotic format does not allow playback on your favourite presentation software. The global ffmpeg syntax reads :

./ffmpeg -i image_%03d.png [options] mavideo.mp4

Windows users will drop the  ./, and will think about adding the ffmpeg binary folder to the environment variables (PATH). The -i command specifies the input file or files to be converted to video. An image sequence will classically be called using regular expressions ; in the example case, files of name image_001.png, image_002.png, etc. Let us now take a look at the encoding options that may prove useful :

Slow motion is achieved with a video filter, called by inserting the following expression where the [options] are located in the original code. Here, the video will be three times slower than the input nominal "speed" :

-filter:v "setpts=3*PTS"

You can change the video size (in our case, force a size of 572x946 pixels)

-s 572x946

Video quality can be set changing the crf option (from 1, best quality, to 31, worst quality, 18 being already excellent quality) :

-crf 18

A ton of other options to rotate, crop, change the luminosity, etc. of your videos is available at the excellent ffmpeg Wiki page.

### Powerpoint compatibility

Microsoft Powerpoint ®, for versions after 2013, is perfectly compatible with the standard output of ffmpeg. Video integration and embedding is therefore seamless. If you want your video to be Powerpoint 2010 compatible, the xvid codec is recommended. The new ffmpeg call syntax is now :

./ffmpeg -i image_%03d.png -c:v libxvid -q:v 4 video.avi

An .avi file is output. Xvid is know to be a lot less efficient than what ffmpeg can natively do, so expect either a decrease in video quality, or a increase in size. By the way, the video quality is now set using -q:v.

### Adobe Reader / Beamer

You can directly include videos in PDF files for Adobe Reader versions above 9 (and Adobe Reader CC) to avoid any stress-related "did I copy my videos along with my PDF file" situation. The solution requires the use of the media9 Beamer package for LaTeX.

\documentclass[...]{beamer}
[...]
\includepackage{media9}
[...]
\begin{document}

Media9 allows multimedia file inclusion in presentations (e.g. : 3d animations, links to Youtube streams, etc.) in addition to videos. I regularly use one simple macro :

\newcommand{\addvideo}[3]{
% Macro to add video :
% Argument 1 : video source location
% Argument 2 : image preview file location
% Argument 3 : width of video
\begin{center}
\includemedia
[
width  = {#3}, addresource = {#1},               %Inclut le fichier source dans le fichier pdf
flashvars = {src=#1 & scaleMode = letterbox}     % Appelle le fichier source dans le lecteur
]
{\includegraphics[width = {#3}]{#2}}{StrobeMediaPlayback.swf} % Arg #2 is used as preview image
\end{center}
}

Including a video called video.mp4 using a cover image called image_example.png for a video width of 8cm will be done with this command line:

\addvideo{video.mp4}{image_exemple.png}{8cm}

The video file is now included in the PDF file. Copying the video file along the PDF file to read the video is, after this step, unnecessary.

Last point : a small compatibility issue with the video player of Adobe Reader will impose a pixel format for your video output. You can set it when calling ffmpeg with the -pix_fmt command:

./ffmpeg -i image_%03d.png -pix_fmt yuv420p video.mp4

Please note that in this case, only even video sizes (472x276, 800x600, etc.) are accepted.

Brice