Skip to content

Instantly share code, notes, and snippets.

@kazz187
Last active August 29, 2015 14:15
Show Gist options
  • Save kazz187/5d1347b127e0b3070ced to your computer and use it in GitHub Desktop.
Save kazz187/5d1347b127e0b3070ced to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def main
source = ARGV[0]
offset_time = ARGV[1].to_f
trim_time = ARGV[2].to_f
#size = '480x270'
size = ARGV[3]
crop = ''
crop = "-crop #{ARGV[4]}" unless ARGV[4].nil?
loop = true
frames = (trim_time * 30).to_i
`ffmpeg -t #{trim_time} -ss #{offset_time} -i #{source} -an -vframes #{frames} %04d.png`
if loop
(1..(frames)).each do |i|
copy_to = frames * 2 - i + 1
`cp #{sprintf("%04d", i)}.png #{sprintf("%04d", copy_to)}.png`
end
end
# `gm convert -delay 3.33 -loop 0 -crop "900x600+200+0" +repage -resize 450x300 *.png #{source}.gif`
`gm convert -delay 3.33 -loop 0 #{crop} +repage -resize #{size} *.png #{source}.gif`
`rm *.png`
`~/workspaces/gifsicle-1.82.1-lossy/mac/gifsicle -O3 --colors 256 --lossy=100 -o #{source}_comp.gif #{source}.gif`
end
main
@kazz187
Copy link
Author

kazz187 commented Feb 16, 2015

./mp42gif shirobako18.mp4 685.1 1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment