Created
July 15, 2022 09:19
-
-
Save enukane/5c8234256a1235e856e0eed1938164cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
require "optparse" | |
OPTS={ | |
:bpm => 60.0, | |
:output => "output.gif", | |
} | |
opt = OptionParser.new | |
opt.on("-b BPM", "--bpm=BPM") {|v| | |
OPTS[:bpm] = v.to_f | |
} | |
opt.on("-o OUTPUT", "--output=OUTPUT") {|v| | |
OPTS[:output] = v | |
} | |
(class<<self;self;end).module_eval do | |
define_method(:usage) do |msg| | |
puts opt.to_s | |
puts "error: #{msg}" if msg | |
exit 1 | |
end | |
end | |
begin | |
rest = opt.parse(ARGV) | |
# XXX: this forbids option-less argument | |
if rest.length != 0 | |
usage | |
end | |
rescue | |
usage $!.to_s | |
end | |
$debug = false | |
def dp str | |
if $debug | |
p str | |
end | |
end | |
system("wget -O parrot.gif https://cultofthepartyparrot.com/parrots/hd/parrot.gif") | |
ORIGINAL_PARROT_PER_SEC = 1/ (10 * 0.05) | |
bpm = OPTS[:bpm] | |
pps = (bpm / 60) | |
speed_rate = 1/ pps * ORIGINAL_PARROT_PER_SEC | |
dp "pps => #{pps}, rate => #{speed_rate}" | |
cmd = "ffmpeg -y -i parrot.gif -filter:v \"setpts=#{speed_rate}*PTS\" #{OPTS[:output]}" | |
dp cmd | |
system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment