How to embed an MP4 inside a PDF?

Viewed 834

I am a happy user of img2pdf. This tool does the minimal amount of work to put a series of JPEG 2000/JPEG/PNG images into a PDF "enveloppe". However I am now faced with a new challenge: embed a MP4 file into a PDF "enveloppe".

I see that commercial tool can do it, as seen at:

Here is one such sample PDF file (no Flash required on windows in this sample):

It seems to have been introduced in ISO 32000-1 (PDF 1.7 Extension Level 5)

I am looking for a solution which will use the Rich Media annotation inside the PDF stream.

There are dozen of duplicated questions on superuser/stackoverflow, which all pretty much refer to imagemagick/convert command line tool. But in my case, convert expand the images into a multi-page PDF (which is not my desired behavior):

$ convert input.mp4 output.pdf
$ pdfinfo output.pdf 
Title:          out
Producer:       https://imagemagick.org
CreationDate:   Wed Aug 19 15:38:01 2020 CEST
ModDate:        Wed Aug 19 15:38:01 2020 CEST
Tagged:         no
UserProperties: no
Suspects:       no
Form:           none
JavaScript:     no
Pages:          1601
Encrypted:      no
Page size:      352 x 288 pts
Page rot:       0
File size:      534407296 bytes
Optimized:      no
PDF version:    1.3

with:

$ convert --version
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib

and

$ file input.mp4 
input.mp4: ISO Media, MP4 Base Media v1 [IS0 14496-12:2003]
$ ffprobe -v quiet -print_format json  -show_streams input.mp4 | grep codec_long_name
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",

How would you embed an MP4 inside a PDF now that Flash support is being removed from Acrobat (Dec 2020) ? The solution should be on the command line (linux based system).

3 Answers

It was common and still possible to use Rich Media Annotation to include 3D animations or Media files within a PDF. Generally you need top end editors such as Acrobat PRO but there are a few LaTeX editor modules that some times work, thus can be PDFLaTeX compiled from Linux command line. for outdated example app see http://www.acrotex.net/blog/?cat=22 and for adobe reply see

> Embedded media, as well as referenced media outside a PDF file, may be played with a variety of player software. (In some situations, the player software may be the conforming reader itself.)

enter image description here

Its NOT recommended except for 3D as most methods require manual over-ridding security measures to STOP runtime applications within a PDF.

SWF/Flash is no longer acceptable for that reason. MicroSoft Edge (pre-chrome) made an attempt at imbedding pdf links to You Tube videos but AFAIK that was abandoned. Thus RMA pdfs can not run in more common browsers they need specialist viewers and the best viewer for Linux is possibly Okular but I cannot run that file in my version.

When opening a 3D file you need to jump through multiple hoops to allow and for floating video it may not even run. your links lead to this media example which can run inline (seen above) or better popout with system application controls.

enter image description here

However in some viewers it needs to be manually exported from the pdf archive as an attachment to be run in a system media player. and for browser presentations it can be a local hyperlink like this.

enter image description here

Using Okular on windows it does not ask prior to running content but that could be becase it found no suitable player, hower it alows me to link to a local file and run that in system viewer.

enter image description here

For everyday presentations its easier to include the media file in a zip with the pdf or PowerPoint presentation for running locally from the pdf.

You can make a python script to embed your video.

Thanks to pyPdf2 api, you can use the addAttachment method to embed your video.

https://github.com/mstamy2/PyPDF2

Related