Home Command line utilities How To Create A Video From PDF Files In Linux
Create A Video From PDF Files

How To Create A Video From PDF Files In Linux

By sk
590 Views

I have a huge collection of PDF files, mostly Linux tutorials, in my tablet PC. Sometimes I feel too lazy to read them from the tablet. 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. 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:

$ sudo dnf install imagemagick

RHEL, CentOS, Scientific Linux:

$ 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.

Hurrah! The movie file is ready!! You can play it on 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 high-end system.

And, that's all for now folks. Hope you find this useful. More good stuffs to come. Stay tuned!

Cheers!

Reference links:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

3 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

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. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More