Skip to content

Instantly share code, notes, and snippets.

@imaimiami
Created March 7, 2014 07:14
Show Gist options
  • Select an option

  • Save imaimiami/9406809 to your computer and use it in GitHub Desktop.

Select an option

Save imaimiami/9406809 to your computer and use it in GitHub Desktop.
Mov to GIF
require 'rubygems'
require 'open-uri'
require 'uri'
require 'streamio-ffmpeg'
require 'rmagick'
@path = ARGV[0]
fileName = File.basename(URI.parse(@path).path)
open(fileName, 'wb') do |output|
open(@path) do |data|
output.write(data.read)
end
end
framerate = 15
movie = FFMPEG::Movie.new fileName
FileUtils.mkdir_p("tmp") unless FileTest.exist?("tmp")
begin
movie.transcode "tmp/%3d.png", "-loglevel error -an -r #{framerate} -s 540x540 -t 00:00:06"
rescue
end
list = Magick::ImageList.new
Dir.glob "tmp/*.png" do |f|
list.push Magick::Image.read(f).first
end
list.delay = (100/framerate).to_i
list.write "animate.gif"
FileUtils.rm_r(Dir.glob('tmp/*'))
Dir.delete("tmp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment