Skip to content

Instantly share code, notes, and snippets.

@t-richards
Created March 5, 2021 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-richards/726b6e7edc4b64b8856890993176adb3 to your computer and use it in GitHub Desktop.
Save t-richards/726b6e7edc4b64b8856890993176adb3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'pathname'
require 'tempfile'
def ffmpeg(*args)
system('ffmpeg', *args)
end
if ARGV.empty?
warn("Usage: #{$PROGRAM_NAME} <video_files>")
exit 1
end
ARGV.each do |input_video|
output_gif = Pathname.new(input_video).sub_ext('.gif').to_s
palette_png = Tempfile.new(['hqg-palette', '.png'])
palette_path = File.expand_path(palette_png.path)
begin
ffmpeg('-i', input_video, '-y', '-vf', 'palettegen', palette_path)
ffmpeg('-i', input_video, '-i', palette_path, '-filter_complex', '[0:v] paletteuse', output_gif)
ensure
palette_png.close
palette_png.unlink
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment