Home Ffmpeg How To Create A Video From PDF Files In Linux

How To Create A Video From PDF Files In Linux

By sk
Published: Updated: 8.8K views

I have a huge collection of PDF files, mostly Linux tutorials, in my tablet PC. Reading text for a long period of time a bit difficult for me. So, I thought It would be better If I can be able to create a video from PDF files and watch it in a big screen devices like a TV or a Computer. Though I have a little working experience with FFMpeg, I am not aware of how to create a movie file using it. After a bit of Google search, I found a good solution to create a video from PDF files in Linux. For those who wanted to make a movie file from a set of PDF files, read on. It is not that difficult.

Create A Video From PDF Files In Linux

For this purpose, you need to install "FFMpeg" and "ImageMagick" software in your system.

To install FFMpeg, refer the following link.

ImageMagick is available in the official repositories of most Linux distributions.

On Arch Linux and derivatives such as Antergos, Manjaro Linux, run the following command to install it.

$ sudo pacman -S imagemagick

Debian, Ubuntu, Linux Mint:

$ sudo apt-get install imagemagick

Fedora, RHEL, CentOS, AlmaLinux and Rocky Linux:

$ sudo dnf install imagemagick

Older RHEL versions and its clones:

$ sudo yum install imagemagick

SUSE, openSUSE:

$ sudo zypper install imagemagick

After installing ffmpeg and imagemagick, convert your PDF file image format such as PNG or JPG like below.

$ convert -density 400 input.pdf picture.png

Here, -density 400 specifies the horizontal resolution of the output image file(s).

The above command will convert all pages in the given PDF file to PNG format. Each page in the PDF file will be converted into a PNG file and they will be saved in the current directory with file name picture-1.png, picture-2.png ... and so on. Please be patient. It will take a while depending on the number of pages in the input PDF file.

Once all pages in the PDF converted into PNG format, run the following command to create a video file from the PNG files.

$ ffmpeg -r 1/10 -i picture-%01d.png -c:v libx264 -r 30 -pix_fmt yuv420p video.mp4

Here,

  • -r 1/10 : Display each image for 10 seconds.
  • -i picture-%01d.png : Reads all pictures that starts with name "picture-", following with 1 digit (%01d) and ending with .png. If the images name comes with 2 digits (I.e picture-10.png, picture11.png etc), use (%02d) in the above command.
  • -c:v libx264 : Output video codec (i.e h264).
  • -r 30 : framerate of output video
  • -pix_fmt yuv420p : Output video resolution
  • video.mp4 : Output video file with .mp4 format.

After the video is created, you can watch it from any devices that supports .mp4 format. Next, I need to find a way to insert a cool music to my video. I hope it won't be difficult either.

If you wanted it in higher pixel resolution, you don't have to start all over again. Just convert the output video file to any other higher/lower resolution of your choice, say 720p, as shown below.

$ ffmpeg -i video.mp4 -vf scale=-1:720 video_720p.mp4

Please note that creating a video using ffmpeg requires a good configuration PC. While converting videos, ffmpeg will consume most of your system resources. I recommend you to do this in a high-end configuration system.

Reference links:

You May Also Like

6 comments

JohnH April 27, 2019 - 12:37 pm

This is so cool! Thanks for sharing! It was exactly what I was looking for. 40 years of journals digitized into pdfs. Now building a python app that randomly builds videos from 6TB of video/audio/pdf…

Reply
sk April 27, 2019 - 12:40 pm

Glad you found it useful.

Reply
QuickHare January 12, 2020 - 4:09 am

To add music, include an additional input and audio codec:

ffmpeg -r 1/10 -i picture-%01d.png -i audio.mp3 -c:v libx264 -r 30 -pix_fmt yuv420p -c:a copy video.mp4

Also, don’t try to resize the video by converting it again. It will be pixelated and not very good. Best to start from scratch and create PNG files which are bigger.

Reply
Larry January 4, 2021 - 3:34 am

Where to see an example of the result?

Reply
sk January 4, 2021 - 10:54 am

If you exclusively didn’t mention the path, the result will be stored in the current working directory.

Reply
mlig September 29, 2022 - 6:09 pm

Thankxxx
Crystal clear

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More