Convert PDF to MP4

I just ran into the problem of having to display a PDF file on my TV. Unfortunately there is no built-in feature, which is able to do so. It is only capable of playing movies, so I had to convert the PDF to a mp4 file.

As I could not find a direct approach, I had to extract all images from the PDF using convert and then concatenate all images into a video stream with ffmpeg.

PDF to PNG’s

convert -density 400 input.pdf pic.png
Option Description
-density 400 Set the horizontal resolution of the image

This will create one picture for every PDF page with the following naming convention pic-<NUM>.

PNG’s to MP4

ffmpeg -r 1/5 -i pic-%02d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
Option Description
pic-%02d.png Read all images from the current folder with the prefix pic-, a following number of 2 digits (%02d) and an ending of .png
-r 1/5 Displays each image for 5 seconds
r 30 Output framerate of 30 fps.
-c:v libx264 Output video codec: h264
pix_fmt yuv420p YUV pixel format

Scale the Movie

As the final movie was >4k, my TV wasn’t able to play it, so I in the last step I had to scale it down to an appropriate resolution of 720p:

ffmpeg -i out.mp4 -vf scale=-1:720  out_720p.mp4

Voila, the final movie plays every page for 5 seconds with a frame rate of 30 frames per second and a horizontal resolution of 720 pixels.

Reference

_

6 comments on “Convert PDF to MP4”

  1. Kenneth Udut Reply

    I’m trying it out now. Thanks! I also made a copy of your instructions. I wanted to go from text –> mp4 and this will work perfectly :)

  2. PaK Reply

    This worked, but I had a problem with transparent png backgrounds being shown as black in the mp4. So I tweaked the convert line; you need to flatten the colour map after you set the background colour.

    convert -density 400 -background white -flatten input.pdf pic.png

Leave a Reply

Your email address will not be published.