Skip to content

Instantly share code, notes, and snippets.

@jastkand
Created November 17, 2013 16:17
Show Gist options
  • Save jastkand/7515043 to your computer and use it in GitHub Desktop.
Save jastkand/7515043 to your computer and use it in GitHub Desktop.
Script that allows to convert pdf file to avi using ffmpeg
require 'RMagick'
require 'fileutils'
def clean_temp(dir)
FileUtils.rm_rf(dir) if File.exists?(dir)
end
pdf = Magick::ImageList.new("input.pdf")
dir = './temp'
clean_temp(dir)
Dir.mkdir(dir)
FileUtils.rm_f('output.mp4')
pdf.each_with_index do |page, index|
# Duplicate first slide to prevent ffmpeg bug
page.write("#{dir}/img#{index}.jpg") if index.zero?
page.write("#{dir}/img#{index + 1}.jpg")
end
`ffmpeg -y -f image2 -r 1/15 -i ./temp/img%d.jpg -c:v libx264 output.mp4`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment