14

I want to make video from pdf file.Is it possible? I created video from images with ffmpeg but not able to create video from PDF files.

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
Preet Sandhu
  • 435
  • 1
  • 8
  • 11

4 Answers4

7

here is script to convert pdf to video:

exec("convert -geometry 1600x1600 -density 200x200 -quality 100 -resize 800x $pdf_path $temp_images");
exec("ffmpeg -loop 1 -f image2 -framerate 0.5 -b 1800 -i $temp_images_wildcard -c:v libx264 -preset slow -tune stillimage -r 5 -t 22 -y $frame_target 2>&1",$output);
llogan
  • 121,796
  • 28
  • 232
  • 243
Preet Sandhu
  • 435
  • 1
  • 8
  • 11
7

Assuming your PDF files are in your working directory, to create a movie file from a set of PDF files you can execute:

exec("mogrify -verbose -density 500 -resize 800 -format png ./*.pdf")
exec("convert -delay 600 *.png movie.mp4")

This requires Imagemagick and Ghostscript to be installed. Works on Linux/Mac OS X/Microsoft Windows. Not vectorial.


If you want to generate some PDF files to test the commands, here is a python script that generates PDF files:

import pandas as pd  
import numpy as np
from matplotlib import pyplot as plt

for i in range(10):
    np.random.seed(i)
    dates = pd.date_range('1/1/2000', periods=50)
    print('dates: {0}'.format(dates))
    df = pd.DataFrame(np.random.randn(len(dates), 1), index=dates.astype(str), columns=['A'])

    print('df: {0}'.format(df))
    plt.figure(figsize=(60,15))
    df.plot(y='A', use_index=True)
    plt.xticks(rotation=70)
    plt.savefig('plot_{0}.pdf'.format(i), dpi=300, bbox_inches='tight')

FYI:

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
2

You could convert the PDF to images and then use your old method to produce the video

Bloafer
  • 1,324
  • 7
  • 12
0

Standard FPS (frames per second) in a video is around 30, that's why keeping it in usual document formats with regular paging is impractical. There's a way to convert a pdf file into images, then you can use it in your video.