How to create a video from a PDF file in Linux
I collected a large number of PDF files on my tablet, mainly Linux tutorials. Sometimes I am too lazy to watch it on a tablet. I think it would be better if I could create a video from a PDF and watch it on a large screen device, such as a TV or computer. Although I have some experience with FFMpeg, I don't know how to use it to create videos. After some Google searches, I came up with a good solution. For those who want to create video files from a set of PDF files, please continue reading. This is not difficult.
Create a video from PDF in Linux
Therefore, you need to install "FFMpeg" and "ImageMagick" in the system ".
To install FFMpeg, see the following link.
- Compiling FFmpeg in Linux supports x264 and x265
- Common FFmpeg commands
- Cross-compile FFmpeg in Ubuntu 16.04
- Install and compile FFmpeg in Ubuntu 16.04
Imagemagick can be found in the official repository of most Linux distributions.
Run the following command to install Arch Linux, Antergos, Manjaro Linux, and other derivative products.
sudo pacman -S imagemagick
Debian, Ubuntu, and Linux Mint:
sudoapt-get install imagemagick
Fedora:
sudo dnf install imagemagick
RHEL, CentOS, and Scientific Linux:
sudoyum install imagemagick
SUSE, openSUSE:
sudo zypper install imagemagick
After ffmpeg and imagemagick are installed, convert your PDF file to an image format, such as PNG or JPG, as shown below.
convert -density 400 input.pdf picture.png
Here,-density 400
Specifies the horizontal resolution of the output image.
The above command will convert all the pages of the specified PDF to PNG format. Every page in the PDF will be converted to a PNG file and saved in the current directory. The file name is:picture-1.png
,picture-2.png
. Depending on the number of pages in the selected PDF, this takes some time.
After converting all pages in PDF to PNG format, run the following command to create a video file from PNG.
ffmpeg -r 1/10-i picture-%01d.png -c:v libx264 -r 30-pix_fmt yuv420p video.mp4
Here:
-r 1/10
: Each image is displayed for 10 seconds.
-i picture-%01d.png
: Readpicture-
Followed by a number (%01d
)..png
All the ending images. If the image name has two digits (that ispicture-10.png
,picture11.png
In the preceding command, use (%02d
).
-c:v libx264
: Output video encoder (h264 ).
-r 30
: The Frame Rate of the output video.
-pix_fmt yuv420p
: Output video resolution
video.mp4
: Output video files in. mp4 format.
Okay. The video file is complete! You can play it on any device that supports the. mp4 format. Next, I need to find a way to insert a cool music for my video. I hope this is not difficult.
If you want a higher resolution, you don't have to start over. You only need to convert the output video file to any other higher/lower resolution, for example, 720 p, as shown below.
ffmpeg -i video.mp4 -vf scale=-1:720 video_720p.mp4
Note that a configured PC is required to use ffmpeg to create a video. During video conversion, ffmpeg consumes a large amount of system resources. I suggest doing this in a high-end system.
That's all. I hope you will find this helpful. There will be better things. Stay tuned!