Skip to content

Instantly share code, notes, and snippets.

@csexton csexton/mov2gif.rb
Created Jul 3, 2019

What would you like to do?
Simple script to convert a mov file to an animated gif. Requires ffmpeg.
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'
options = {
rate: 30,
log: 0,
} do |opts|
opts.banner = "Usage: mov2gif [options] file"
opts.on("-v", "--verbose [LOG_LEVEL]", "Set logging level") do |v|
options[:log] = v
opts.on("-r", "--rate [RATE]", "Set frame rate (Hz value, fraction or abbreviation)") do |v|
options[:rate] = v
in_file = ARGV.first
out_file = File.basename(in_file, ".*" ) + ".gif"
unless File.file?(in_file)
STDERR.puts "ERROR: #{in_file} does not exist"
exit 1
cmd = %[ffmpeg -i "#{in_file}" -vf "scale='min(1280,iw)':-1" -pix_fmt rgb8 -r #{options[:rate]} -f gif -v #{options[:log]} -stats #{out_file}]
puts "Converting #{in_file} to #{out_file}"
puts "--> #{cmd}"
system cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.