Created
March 5, 2021 18:15
-
-
Save t-richards/726b6e7edc4b64b8856890993176adb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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